From f923add0a9b6bd17d43f72c21eec4e01e19240cf Mon Sep 17 00:00:00 2001 From: zilio nicolas Date: Tue, 7 Jul 2015 11:12:52 +0200 Subject: clean version for locks --- pcitool/cli.c | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) (limited to 'pcitool') diff --git a/pcitool/cli.c b/pcitool/cli.c index 9eeb046..a6224e3 100644 --- a/pcitool/cli.c +++ b/pcitool/cli.c @@ -1,3 +1,4 @@ +#define _XOPEN_SOURCE 700 #define _POSIX_C_SOURCE 200112L #define _BSD_SOURCE @@ -37,6 +38,7 @@ #include "error.h" #include "debug.h" #include "model.h" +#include "locking.h" /* defines */ #define MAX_KBUF 14 @@ -89,7 +91,8 @@ typedef enum { MODE_ALLOC_KMEM, MODE_LIST_KMEM, MODE_READ_KMEM, - MODE_FREE_KMEM + MODE_FREE_KMEM, + MODE_FREE_LOCKS } MODE; typedef enum { @@ -167,7 +170,8 @@ typedef enum { OPT_VERIFY, OPT_WAIT, OPT_MULTIPACKET, - OPT_VERBOSE + OPT_VERBOSE, + OPT_FREE_LOCKS } OPTIONS; static struct option long_options[] = { @@ -219,6 +223,7 @@ static struct option long_options[] = { {"multipacket", no_argument, 0, OPT_MULTIPACKET }, {"wait", no_argument, 0, OPT_WAIT }, {"help", no_argument, 0, OPT_HELP }, + {"free-locks", no_argument, 0, OPT_FREE_LOCKS}, { 0, 0, 0, 0 } }; @@ -272,6 +277,7 @@ void Usage(int argc, char *argv[], const char *format, ...) { " block is specified as: use:block_number\n" " --alloc-kernel-memory - Allocate kernel buffers (DANGEROUS)\n" " --free-kernel-memory - Cleans lost kernel space buffers (DANGEROUS)\n" +" --free-locks - Cleans locks allocated during pcitool program use(dangerous in a concurrential model)\n" " dma - Remove all buffers allocated by DMA subsystem\n" " #number - Remove all buffers with the specified use id\n" "\n" @@ -2570,6 +2576,9 @@ int main(int argc, char **argv) { event = stmp; } break; + case OPT_FREE_LOCKS: + mode=MODE_FREE_LOCKS; + break; case OPT_TRIGGER: if ((mode != MODE_INVALID)&&((mode != MODE_GRAB)||(grab_mode&GRAB_MODE_TRIGGER))) Usage(argc, argv, "Multiple operations are not supported"); @@ -2949,7 +2958,6 @@ int main(int argc, char **argv) { model_info = pcilib_get_model_description(handle); dma_info = pcilib_get_dma_description(handle); - switch (mode) { case MODE_WRITE: if (((argc - optind) == 1)&&(*argv[optind] == '*')) { @@ -3137,6 +3145,9 @@ int main(int argc, char **argv) { } switch (mode) { + case MODE_FREE_LOCKS: + pcilib_clean_all_locks(handle); + break; case MODE_INFO: Info(handle, model_info); break; -- cgit v1.2.3 From 16ecf368c5cb4bebc3f5330bd0f25db06606f862 Mon Sep 17 00:00:00 2001 From: "Suren A. Chilingaryan" Date: Thu, 6 Aug 2015 02:27:23 +0200 Subject: In case of problematic locks report the error --- pcitool/cli.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'pcitool') diff --git a/pcitool/cli.c b/pcitool/cli.c index 5df175d..6551f7b 100644 --- a/pcitool/cli.c +++ b/pcitool/cli.c @@ -2444,9 +2444,9 @@ int ListLocks(pcilib_t *ctx, int verbose) { pcilib_lock_id_t i; if (verbose) - printf("ID Refs Flags Locked Name\n"); + printf("ID Refs Flags Locked Name\n"); else - printf("ID Refs Flags Name\n"); + printf("ID Refs Flags Name\n"); printf("--------------------------------------------------------------------------------\n"); for (i = 0; i < PCILIB_MAX_LOCKS; i++) { @@ -2468,13 +2468,13 @@ int ListLocks(pcilib_t *ctx, int verbose) { switch (err) { case 0: pcilib_unlock(lock); - printf("No "); + printf("No "); break; case PCILIB_ERROR_TIMEOUT: - printf("Yes "); + printf("Yes "); break; default: - printf("Error "); + printf("Err: %3i ", err); } } printf("%s\n", name); -- cgit v1.2.3 From 55783eb24e983786056f4ba7925aa23fca13c79e Mon Sep 17 00:00:00 2001 From: "Suren A. Chilingaryan" Date: Wed, 12 Aug 2015 20:25:35 +0200 Subject: Fix support of older systems: Remove C11 derective and add rt library to the link list --- CMakeLists.txt | 6 ++++-- pcilib/CMakeLists.txt | 2 +- pcitool/CMakeLists.txt | 2 +- 3 files changed, 6 insertions(+), 4 deletions(-) (limited to 'pcitool') diff --git a/CMakeLists.txt b/CMakeLists.txt index bbe5a74..337a366 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -12,6 +12,8 @@ set(DISABLE_PCITOOL FALSE CACHE BOOL "Build only the library") find_package(PkgConfig REQUIRED) find_package(Threads REQUIRED) +set(EXTRA_SYSTEM_LIBS -lrt) + #Check in sibling directory if (NOT DISABLE_PCITOOL) pkg_check_modules(FASTWRITER fastwriter REQUIRED) @@ -19,8 +21,8 @@ endif (NOT DISABLE_PCITOOL) check_include_files(stdatomic.h HAVE_STDATOMIC_H) -add_definitions("-fPIC --std=c11 -Wall -O2 -gdwarf-2 -g3") -#add_definitions("-fPIC --std=c11 -Wall -O2") +add_definitions("-fPIC --std=c99 -Wall -O2 -gdwarf-2 -g3") +#add_definitions("-fPIC --std=c99 -Wall -O2") include(cmake/version.cmake) VERSION_TO_VARS(${PCILIB_VERSION} PCILIB_VERSION_MAJOR PCILIB_VERSION_MINOR PCILIB_VERSION_MICRO) diff --git a/pcilib/CMakeLists.txt b/pcilib/CMakeLists.txt index 79b15c2..be59cb7 100644 --- a/pcilib/CMakeLists.txt +++ b/pcilib/CMakeLists.txt @@ -5,7 +5,7 @@ include_directories( set(HEADERS pcilib.h pci.h export.h bar.h fifo.h model.h bank.h register.h kmem.h irq.h locking.h lock.h dma.h event.h plugin.h tools.h error.h debug.h env.h version.h config.h) add_library(pcilib SHARED pci.c export.c bar.c fifo.c model.c bank.c register.c kmem.c irq.c locking.c lock.c dma.c event.c plugin.c tools.c error.c debug.c env.c ) -target_link_libraries(pcilib dma protocols ${CMAKE_THREAD_LIBS_INIT} ${UFODECODE_LIBRARIES} ${CMAKE_DL_LIBS}) +target_link_libraries(pcilib dma protocols ${CMAKE_THREAD_LIBS_INIT} ${UFODECODE_LIBRARIES} ${CMAKE_DL_LIBS} ${EXTRA_SYSTEM_LIBS}) add_dependencies(pcilib dma protocols) install(TARGETS pcilib diff --git a/pcitool/CMakeLists.txt b/pcitool/CMakeLists.txt index 1b21041..fc88de6 100644 --- a/pcitool/CMakeLists.txt +++ b/pcitool/CMakeLists.txt @@ -15,7 +15,7 @@ if (NOT DISABLE_PCITOOL) add_dependencies(pci pcitool) target_link_libraries(pci pcilib ${FASTWRITER_LIBRARIES}) set_target_properties(pci PROPERTIES - LINK_FLAGS ${CMAKE_THREAD_LIBS_INIT} + LINK_FLAGS "${CMAKE_THREAD_LIBS_INIT} ${EXTRA_SYSTEM_LIBS}" ) #set_target_properties(pci PROPERTIES -- cgit v1.2.3 From c8fe6103fa27308822592a8c3e7dc883fd299c3a Mon Sep 17 00:00:00 2001 From: "Suren A. Chilingaryan" Date: Fri, 14 Aug 2015 01:36:38 +0200 Subject: Improve bad events counting --- pcitool/cli.c | 55 ++++++++++++++++++++++++++++++++++--------------------- 1 file changed, 34 insertions(+), 21 deletions(-) (limited to 'pcitool') diff --git a/pcitool/cli.c b/pcitool/cli.c index 6551f7b..57801ab 100644 --- a/pcitool/cli.c +++ b/pcitool/cli.c @@ -1283,7 +1283,7 @@ typedef struct { int verbose; pcilib_timeout_t timeout; size_t run_time; - size_t trigger_time; + size_t trigger_time; size_t max_triggers; pcilib_event_flags_t flags; FORMAT format; @@ -1295,17 +1295,19 @@ typedef struct { volatile int run_flag; volatile int writing_flag; - struct timeval first_frame; + struct timeval first_frame; struct timeval last_frame; - size_t last_num; - + size_t last_num, last_id; + size_t trigger_failed; size_t trigger_count; - size_t event_count; - size_t incomplete_count; - size_t broken_count; - size_t missing_count; - size_t storage_count; + size_t event_count; /**< Total number of events (including bad ones, but excluding events expected, but not reported by hardware) */ + size_t incomplete_count; /**< Broken events, we even can't extract appropriate block of raw data */ + size_t broken_count; /**< Broken events, error while decoding in the requested format */ + size_t empty_count; /**< Broken events, no associated data or unknown */ + size_t missing_count; /**< Missing events, not received from the hardware */ + size_t dropped_count; /**< Missing events, dropped due slow decoding/copying performance */ + size_t storage_count; /**< Missing events, dropped due to slowness of the storage subsystem */ struct timeval start_time; struct timeval stop_time; @@ -1333,12 +1335,13 @@ int GrabCallback(pcilib_event_id_t event_id, pcilib_event_info_t *info, void *us ctx->missing_count += missing_count; #ifdef PCILIB_DEBUG_MISSING_EVENTS if (missing_count) - pcilib_debug(MISSING_EVENTS, "%zu missing events between %zu and %zu", missing_count, ctx->last_num, info->seqnum); + pcilib_debug(MISSING_EVENTS, "%zu missing events between %zu (hwid: %zu) and %zu (hwid: %zu)", missing_count, ctx->last_id, ctx->last_num, event_id, info->seqnum); #endif /* PCILIB_DEBUG_MISSING_EVENTS */ } ctx->last_num = info->seqnum; - + ctx->last_id = event_id; + if (info->flags&PCILIB_EVENT_INFO_FLAG_BROKEN) { ctx->incomplete_count++; return PCILIB_STREAMING_CONTINUE; @@ -1351,9 +1354,19 @@ int GrabCallback(pcilib_event_id_t event_id, pcilib_event_info_t *info, void *us default: data = pcilib_get_data(handle, event_id, PCILIB_EVENT_RAW_DATA, &size); } - + if (!data) { - ctx->broken_count++; + int err = (int)size; + switch (err) { + case PCILIB_ERROR_OVERWRITTEN: + ctx->dropped_count++; + break; + case PCILIB_ERROR_INVALID_DATA: + ctx->broken_count++; + break; + default: + ctx->empty_count++; + } return PCILIB_STREAMING_CONTINUE; } @@ -1386,7 +1399,7 @@ int GrabCallback(pcilib_event_id_t event_id, pcilib_event_info_t *info, void *us err = pcilib_return_data(handle, event_id, ctx->data, data); if (err) { - ctx->missing_count++; + ctx->dropped_count++; fastwriter_cancel(ctx->writer); return PCILIB_STREAMING_CONTINUE; } @@ -1498,7 +1511,7 @@ void GrabStats(GRABContext *ctx, struct timeval *end_time) { total = ctx->event_count + ctx->missing_count; } - good = ctx->event_count - ctx->broken_count - ctx->incomplete_count - ctx->storage_count; + good = ctx->event_count - ctx->broken_count - ctx->incomplete_count - ctx->storage_count - ctx->empty_count - ctx->dropped_count; if (ctx->event_count > 1) { fps = (ctx->event_count - 1) / (1.*fps_duration/1000000); @@ -1554,11 +1567,11 @@ void GrabStats(GRABContext *ctx, struct timeval *end_time) { printf("Good: "); PrintNumber(good); printf(", Dropped: "); - PrintNumber(ctx->storage_count); + PrintNumber(ctx->dropped_count + ctx->storage_count); printf(", Bad: "); - PrintNumber(ctx->incomplete_count); + PrintNumber(ctx->incomplete_count + ctx->broken_count); printf(", Empty: "); - PrintNumber(ctx->broken_count); + PrintNumber(ctx->empty_count); } printf(", Lost: "); PrintNumber(ctx->missing_count); @@ -1573,11 +1586,11 @@ void GrabStats(GRABContext *ctx, struct timeval *end_time) { printf("Good: "); PrintPercent(good, total); printf("%% Dropped: "); - PrintPercent(ctx->storage_count, total); + PrintPercent(ctx->dropped_count + ctx->storage_count, total); printf("%% Bad: "); - PrintPercent(ctx->incomplete_count, total); + PrintPercent(ctx->incomplete_count + ctx->broken_count, total); printf("%% Empty: "); - PrintPercent(ctx->broken_count, total); + PrintPercent(ctx->empty_count, total); } printf("%% Lost: "); -- cgit v1.2.3 From e256f2f50cc579a89e8b9460e192097e99e36ccb Mon Sep 17 00:00:00 2001 From: "Suren A. Chilingaryan" Date: Tue, 18 Aug 2015 07:02:32 +0200 Subject: Add support for kernel 4.1 --- driver/Makefile | 2 +- driver/base.h | 10 +++++----- pcitool/CMakeLists.txt | 2 +- 3 files changed, 7 insertions(+), 7 deletions(-) (limited to 'pcitool') diff --git a/driver/Makefile b/driver/Makefile index e353228..3a242dd 100644 --- a/driver/Makefile +++ b/driver/Makefile @@ -3,7 +3,7 @@ obj-m := pciDriver.o pciDriver-objs := base.o int.o umem.o kmem.o sysfs.o ioctl.o KERNELDIR ?= /lib/modules/$(shell uname -r)/build -INSTALLDIR ?= /lib/modules/$(shell uname -r)/extra +INSTALLDIR ?= /lib/modules/$(shell uname -r)/kernel/extra PWD := $(shell pwd) EXTRA_CFLAGS += -I$(M)/.. diff --git a/driver/base.h b/driver/base.h index 9384e2d..b976d3f 100644 --- a/driver/base.h +++ b/driver/base.h @@ -68,14 +68,14 @@ static dev_t pcidriver_devt; static atomic_t pcidriver_deviceCount; /* Sysfs attributes */ -static DEVICE_ATTR(mmap_mode, (S_IRUGO | S_IWUGO), pcidriver_show_mmap_mode, pcidriver_store_mmap_mode); -static DEVICE_ATTR(mmap_area, (S_IRUGO | S_IWUGO), pcidriver_show_mmap_area, pcidriver_store_mmap_area); +static DEVICE_ATTR(mmap_mode, 0664, pcidriver_show_mmap_mode, pcidriver_store_mmap_mode); +static DEVICE_ATTR(mmap_area, 0664, pcidriver_show_mmap_area, pcidriver_store_mmap_area); static DEVICE_ATTR(kmem_count, S_IRUGO, pcidriver_show_kmem_count, NULL); static DEVICE_ATTR(kbuffers, S_IRUGO, pcidriver_show_kbuffers, NULL); -static DEVICE_ATTR(kmem_alloc, S_IWUGO, NULL, pcidriver_store_kmem_alloc); -static DEVICE_ATTR(kmem_free, S_IWUGO, NULL, pcidriver_store_kmem_free); +static DEVICE_ATTR(kmem_alloc, 0220, NULL, pcidriver_store_kmem_alloc); +static DEVICE_ATTR(kmem_free, 0220, NULL, pcidriver_store_kmem_free); static DEVICE_ATTR(umappings, S_IRUGO, pcidriver_show_umappings, NULL); -static DEVICE_ATTR(umem_unmap, S_IWUGO, NULL, pcidriver_store_umem_unmap); +static DEVICE_ATTR(umem_unmap, 0220, NULL, pcidriver_store_umem_unmap); #ifdef ENABLE_IRQ static DEVICE_ATTR(irq_count, S_IRUGO, pcidriver_show_irq_count, NULL); diff --git a/pcitool/CMakeLists.txt b/pcitool/CMakeLists.txt index fc88de6..4aea142 100644 --- a/pcitool/CMakeLists.txt +++ b/pcitool/CMakeLists.txt @@ -12,7 +12,7 @@ link_directories( if (NOT DISABLE_PCITOOL) add_executable(pci cli.c sysinfo.c formaters.c) set(HEADERS ${HEADERS} sysinfo.h formaters.h) - add_dependencies(pci pcitool) + add_dependencies(pci pcilib) target_link_libraries(pci pcilib ${FASTWRITER_LIBRARIES}) set_target_properties(pci PROPERTIES LINK_FLAGS "${CMAKE_THREAD_LIBS_INIT} ${EXTRA_SYSTEM_LIBS}" -- cgit v1.2.3