小编Xat*_*ian的帖子

Eventloop has high ksoftirqd load; nginx does not but does same system-calls. Why?

I wrote some code that has an epoll-eventloop, accepts new connections and pretends to be a http-server. The posted code is the absolute minimum ... I removed everything (including all error-checks) to make it as short and to the point as possible:

#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <sys/epoll.h>
#include <sys/socket.h>
#include <netinet/ip.h>
#include <netinet/in.h>
#include <sys/uio.h>
#include <unistd.h>


int main () {
    int servFd = socket (AF_INET, SOCK_STREAM | SOCK_NONBLOCK | SOCK_CLOEXEC, IPPROTO_IP);
    int value = 1;
    setsockopt …
Run Code Online (Sandbox Code Playgroud)

c linux performance epoll event-loop

19
推荐指数
1
解决办法
714
查看次数

GCC宏扩展调用另一个宏

我正在用C(gcc)编写一个应用程序,它做了很多字符串比较.始终是一个带有很长编译时常量字符串列表的未知/动态字符串.所以我想我对动态字符串进行散列并将结果散列与常量字符串的预计算散列进行比较.

这样做我在一个函数(对于动态运行时字符串)和宏中使用哈希算法,以便gcc在编译时评估哈希.

我懂了:

#define HASH_CALC(h, s) ((h) * 33 + *(s))
#define HASH_CALC1(s) (HASH_CALC(hash_calc_start, s))
#define HASH_CALC2(s) (HASH_CALC(HASH_CALC1(s), s + 1))
#define HASH_CALC3(s) (HASH_CALC(HASH_CALC2(s), s + 2))
#define HASH_CALC4(s) (HASH_CALC(HASH_CALC3(s), s + 3))
#define HASH_CALC5(s) (HASH_CALC(HASH_CALC4(s), s + 4))
//--> cut ... goes till HASH_CALC32

static const unsigned long hash_calc_start = 5381;
unsigned long hash_str (const char* c);

void func () {
    //This string is not constant ... just in this case to show something
    char dynStr = "foo";
    unsigned …
Run Code Online (Sandbox Code Playgroud)

c macros gcc

7
推荐指数
1
解决办法
1995
查看次数

标签 统计

c ×2

epoll ×1

event-loop ×1

gcc ×1

linux ×1

macros ×1

performance ×1