Enable pedantic and use C11 std

This commit is contained in:
Rodrigo Arias 2021-09-28 19:21:22 +02:00
parent 13b270a00b
commit 6a3ea0907a
7 changed files with 26 additions and 7 deletions

View File

@ -1,4 +1,5 @@
CFLAGS=-fPIC CFLAGS=-fPIC
CFLAGS+=-std=c11 -pedantic -Werror -Wformat
# Debug flags # Debug flags
#CFLAGS+=-fsanitize=address #CFLAGS+=-fsanitize=address

2
dump.c
View File

@ -43,7 +43,7 @@ void emit(struct ovni_stream *stream, struct ovni_ev *ev)
delta = clock - stream->lastclock; delta = clock - stream->lastclock;
printf("%d.%d.%d %c %c %c % 20lu % 15ld ", printf("%d.%d.%d %c %c %c % 20ld % 15ld ",
stream->loom, stream->proc, stream->tid, stream->loom, stream->proc, stream->tid,
ev->header.model, ev->header.class, ev->header.value, clock, delta); ev->header.model, ev->header.class, ev->header.value, clock, delta);

8
emu.c
View File

@ -1,3 +1,5 @@
#define _POSIX_C_SOURCE 200112L
#include <stdio.h> #include <stdio.h>
#include <stdint.h> #include <stdint.h>
#include <stdlib.h> #include <stdlib.h>
@ -483,7 +485,11 @@ load_clock_offsets(struct ovni_emu *emu)
} }
/* Ignore header line */ /* Ignore header line */
fgets(buf, 1024, f); if(fgets(buf, 1024, f) == NULL)
{
perror("fgets failed");
exit(EXIT_FAILURE);
}
while(1) while(1)
{ {

12
ovni.c
View File

@ -9,7 +9,6 @@
#include <linux/limits.h> #include <linux/limits.h>
#include <errno.h> #include <errno.h>
#include <sys/stat.h> #include <sys/stat.h>
#include <sys/syscall.h>
#include <sys/mman.h> #include <sys/mman.h>
#include <stdatomic.h> #include <stdatomic.h>
#include <assert.h> #include <assert.h>
@ -22,6 +21,11 @@
#include "ovni_trace.h" #include "ovni_trace.h"
#include "parson.h" #include "parson.h"
#ifndef gettid
# include <sys/syscall.h>
# define gettid() ((pid_t)syscall(SYS_gettid))
#endif
//#define ENABLE_SLOW_CHECKS //#define ENABLE_SLOW_CHECKS
//#define USE_RDTSC //#define USE_RDTSC
@ -69,7 +73,7 @@ create_trace_stream()
char path[PATH_MAX]; char path[PATH_MAX];
fprintf(stderr, "create thread stream tid=%d gettid=%d rproc.proc=%d rproc.ready=%d\n", fprintf(stderr, "create thread stream tid=%d gettid=%d rproc.proc=%d rproc.ready=%d\n",
rthread.tid, syscall(SYS_gettid), rproc.proc, rproc.ready); rthread.tid, gettid(), rproc.proc, rproc.ready);
snprintf(path, PATH_MAX, "%s/thread.%d", rproc.dir, rthread.tid); snprintf(path, PATH_MAX, "%s/thread.%d", rproc.dir, rthread.tid);
@ -294,7 +298,7 @@ uint64_t rdtsc(void)
uint32_t lo, hi; uint32_t lo, hi;
// RDTSC copies contents of 64-bit TSC into EDX:EAX // RDTSC copies contents of 64-bit TSC into EDX:EAX
asm volatile("rdtsc" : "=a" (lo), "=d" (hi)); __asm__ volatile("rdtsc" : "=a" (lo), "=d" (hi));
return (uint64_t) hi << 32 | lo; return (uint64_t) hi << 32 | lo;
} }
@ -782,7 +786,7 @@ load_stream_buf(struct ovni_stream *stream, struct ovni_ethread *thread)
if(st.st_size == 0) if(st.st_size == 0)
{ {
err("warning: stream %s is empty\n", stream->tid); err("warning: stream %d is empty\n", stream->tid);
stream->size = 0; stream->size = 0;
stream->buf = NULL; stream->buf = NULL;
stream->active = 0; stream->active = 0;

1
ovni.h
View File

@ -6,6 +6,7 @@
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include <linux/limits.h> #include <linux/limits.h>
#include <sys/types.h>
#include <limits.h> #include <limits.h>
#include "parson.h" #include "parson.h"

View File

@ -1,3 +1,5 @@
#define _POSIX_C_SOURCE 200112L
#include <limits.h> #include <limits.h>
#include <time.h> #include <time.h>
#include <stdio.h> #include <stdio.h>
@ -6,6 +8,7 @@
#include <math.h> #include <math.h>
#include <unistd.h> #include <unistd.h>
#include <assert.h> #include <assert.h>
#include <time.h>
#include "ovni.h" #include "ovni.h"
@ -400,7 +403,7 @@ do_work(struct options *options, int rank)
} }
if(drift_mode) if(drift_mode)
usleep(options->drift_wait * 1000 * 1000); sleep(options->drift_wait);
} }
} }

View File

@ -1,9 +1,13 @@
#define _POSIX_C_SOURCE 200112L
#define _GNU_SOURCE
#include <stdint.h> #include <stdint.h>
#include <stddef.h> #include <stddef.h>
#include <stdio.h> #include <stdio.h>
#include <unistd.h> #include <unistd.h>
#include <sys/types.h> #include <sys/types.h>
#include <linux/limits.h> #include <linux/limits.h>
#include <limits.h>
#include "ovni.h" #include "ovni.h"