iouring的demo性能测试程序

/*多线程多实例,注意线程的绑定,一个core绑定一个sq线程,一个或者多个core绑定一个或多个work线程,还有控制worker线程个数,还有numa的绑定

编译命令: gcc -g -o iouring www_iouring.c -L/usr/lib -luring

执行命令: numactl --cpunodebind=1 --membind=1 ./iouring io_uring.conf

*/

#define _GNU_SOURCE//使用sched.h的时候需要添加GNU宏

#include <stdio.h>

#include <string.h>

#include <stdlib.h>

#include <liburing.h>

#include <fcntl.h>

#include <unistd.h>

#include <sys/stat.h>

#include <sys/types.h>

#include <errno.h>

#include <ctype.h>

#include <pthread.h>

#include <time.h>

#include <sched.h>

#define MAX_LINE_LENGTH 256

#define MAX_FILENAME_COUNT 52

#define IOWQ_CPU 0

#define OBJ_NUM 1

#define CPU_CORE 2

//Parameters in the configuration file

typedef struct {

    int sqthread_poll;

    int direct;

    int time_based;

    int group_reporting;

    int iodepth;

    int numjobs;

    int runtime;

    int ramp_time;

    int rwmixread;

    int sqthread_cpu;

    char rw[50];

    int bs;

} global_config;

typedef struct  {

    char filename[MAX_FILENAME_COUNT][MAX_LINE_LENGTH];

    int filename_count;

}job_config;

off_t getFileSize(int fd) {

    off_t offset = lseek(fd, 0, SEEK_CUR);

    return offset;

}

//Read configuration file

void read_config(const char *filename, global_config *global, job_config *job) {

    FILE *file = fopen(filename, "r");

    if (!file) {

        perror("Error opening config file");

        exit(EXIT_FAILURE);

    }

    char line[MAX_LINE_LENGTH];

    char section[MAX_LINE_LENGTH] = "";

    job->filename_count = 0;  // Initialize filename count

    while (fgets(line, sizeof(line), file)) {

        // Remove trailing newline character

        line[strcspn(line, "\n")] = '\0';

        // Ignore empty lines and comments

        if (line[0] == '\0' || line[0] == '#') {

            continue;

        }

        // If it's a section title, update the current section name

        if (line[0] == '[' && line[strlen(line) - 1] == ']') {

            sscanf(line, "[%[^]]", section);

            continue;

        }

        // Parse key-value pairs

        char key[MAX_LINE_LENGTH];

        char value[MAX_LINE_LENGTH];

        sscanf(line, "%[^=]=%s", key, value);

        // Store parameter values in the appropriate structure based on the current section name

        if (strcmp(section, "global") == 0) {

            // Global section parameters

            if (strcmp(key, "sqthread_poll") == 0) {

                global->sqthread_poll = atoi(value);

            }  else if (strcmp(key, "direct") == 0) {

                global->direct = atoi(value);

            } else if (strcmp(key, "time_based") == 0) {

                global->time_based = atoi(value);

            } else if (strcmp(key, "group_reporting") == 0) {

                global->group_reporting = atoi(value);

            } else if (strcmp(key, "bs") == 0) {

                global->bs = atoi(value);

            } else if (strcmp(key, "rw") == 0) {

                strcpy(global->rw, value);

            } else if (strcmp(key, "numjobs") == 0) {

                global->numjobs = atoi(value);

  &nbs

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值