/* bench_sqpoll.c — io_uring con SQPOLL contra io_uring normal y contra pread.
*
* Cierra el experimento 4 de SDD 25 seccion 9: SQPOLL pide CAP_SYS_NICE, asi que la corrida
* original no pudo mirarlo. La pregunta que dejo abierta T12: io_uring pierde sobre datos ya
* cacheados porque el cruce al kernel no se amortiza — con SQPOLL NO HAY cruce (un hilo del
* kernel consume la cola), asi que este es el caso donde deberia ganar.
*
* Uso: bench_sqpoll
* Se compila con: cc -O2 -o bench_sqpoll bench_sqpoll.c -luring
*/
#define _GNU_SOURCE
#include
#include
#include
#include
#include
#include
#include
#include
#define MB (1024*1024)
#define SIZE (64*MB)
#define BS 4096
#define ROUNDS 7
#define DEPTH 32
#define OPS 50000
static volatile long sink;
static inline double now_ns(void){ struct timespec t; clock_gettime(CLOCK_MONOTONIC,&t); return t.tv_sec*1e9+t.tv_nsec; }
static int cmpd(const void*a,const void*b){ double x=*(const double*)a,y=*(const double*)b; return (x>y)-(x \n",argv[0]); return 2; }
char path[512]; snprintf(path,sizeof path,"%s/sqpoll.bin",argv[1]);
int fd=open(path,O_CREAT|O_RDWR|O_TRUNC,0644);
if(fd<0){ fprintf(stderr,"no pude crear %s: %s\n",path,strerror(errno)); return 1; }
char *b=malloc(MB); memset(b,0x5A,MB);
for(int i=0;iflags|=IOSQE_FIXED_FILE;
}
io_uring_submit_and_wait(&ring,batch);
struct io_uring_cqe *c; unsigned h; int seen=0;
io_uring_for_each_cqe(&ring,h,c){ if(c->res<0) sink=c->res; seen++; }
io_uring_cq_advance(&ring,seen);
done+=batch;
}
r[q]=(now_ns()-t0)/(double)OPS;
}
report(usar_fijo?"io_uring SQPOLL (fd registrado)":"io_uring SQPOLL (fd normal)",r,ROUNDS,OPS);
io_uring_queue_exit(&ring);
} else printf("SQPOLL: no disponible (%s) — pide CAP_SYS_NICE\n",strerror(errno));
unlink(path); close(fd);
return 0;
}