remove unused code
authorLaurent Mazet <mazet@softndesign.org>
Thu, 8 May 2025 06:43:06 +0000 (08:43 +0200)
committerLaurent Mazet <mazet@softndesign.org>
Thu, 8 May 2025 06:43:06 +0000 (08:43 +0200)
core.c
core.h
rdtsc.h [deleted file]
task.c
task.h

diff --git a/core.c b/core.c
index bd614820a7044219f2047413bd088745c06d330c..4e4bf8d771206a651d618b8f5712ca7a8eb29848 100644 (file)
--- a/core.c
+++ b/core.c
@@ -20,7 +20,6 @@
 #include <sys/time.h>
 #include <unistd.h>
 
-#include "rdtsc.h"
 #include "verbose.h"
 
 #include "core.h"
@@ -79,42 +78,4 @@ int cpu_setaffinity (const char *cpu_list)
     return pthread_setaffinity_np(pthread_self (), sizeof(cpu_set_t), &cpuset);
 }
 
-/**
-   Cpu clock
-*/
-static double cpu_clock = 1;
-
-
-/**
-    Internal funciton, executed at load time to calibrate cpu clock
-*/
-void __attribute__((constructor)) _core_init_cpu_clock (void)
-{
-    struct timeval tv1, tv2;
-    long long int ts1, ts2;
-
-    gettimeofday (&tv1, NULL);
-    ts1 = rdtsc ();
-
-    usleep (100000);
-
-    gettimeofday (&tv2, NULL);
-    ts2 = rdtsc ();
-
-    double delta = ((double)tv2.tv_sec + tv2.tv_usec * 1e-6) -
-        ((double)tv1.tv_sec + tv1.tv_usec * 1e-6);
-
-    cpu_clock = (ts2 - ts1) / delta;
-}
-
-unsigned long long tsc2diff (unsigned long long tsc1, unsigned long long tsc2)
-{
-    return (tsc1 > tsc2) ? tsc1 - tsc2 : tsc2 + (~tsc1) + 1;
-}
-
-float tsc2ms (unsigned long long delta_tsc)
-{
-    return (float) (delta_tsc / cpu_clock * 1e6f);
-}
-
 /* vi:set tabstop=4 expandtab shiftwidth=4: this line set vi mode */
diff --git a/core.h b/core.h
index 639333f1c1bacf97bc27c404ab22f412a9e7eee5..d1588f0d1d660cc98bde7b708843033c3c95340d 100644 (file)
--- a/core.h
+++ b/core.h
@@ -49,23 +49,6 @@ int enable_realtime (int prio);
 */
 int cpu_setaffinity (const char *cpu_list);
 
-/**
-   Compute the difference between two cycle counters
-
-   @param tsc1 initial cycle counter
-   @param tsc1 last cycle counter
-   @return cycle counter difference
-*/
-unsigned long long tsc2diff (unsigned long long tsc1, unsigned long long tsc2);
-
-/**
-   Evaluation a number of cycles in milisecond
-
-   @param delta_tsc number of cycles
-   @return number of miliseconds
-*/
-float tsc2ms (unsigned long long delta_tsc);
-
 __END_DECLS
 
 #endif /* __CORE_H__ */
diff --git a/rdtsc.h b/rdtsc.h
deleted file mode 100644 (file)
index 2cbf5de..0000000
--- a/rdtsc.h
+++ /dev/null
@@ -1,46 +0,0 @@
-/*
-  File name        : rdtsc.h
-  Projet           : MERLIN
-  Date of creation : 2025/05/02
-  Version          : 1.0
-  Copyright        : Thales SIX
-  Author           : Laurent Mazet <laurent.mazet@thalesgroup.com>
-
-  Description      : This file contains rdtsc inline function
-
-  History          :
-  - initial version
-*/
-
-#ifndef __RDTSC_H__
-#define __RDTSC_H__
-
-#include <stdint.h>
-#include <sys/cdefs.h>
-
-__BEGIN_DECLS
-
-/**
-    Get RDTSC counter
-
-    @return counter
-*/
-#ifdef __i386
-static __inline__ int64_t rdtsc (void) {
-     int64_t x;
-     __asm__ volatile ("rdtsc" : "=A" (x));
-     return x;
-}
-#elif __amd64
-static __inline__ int64_t rdtsc (void) {
-     int64_t a, d;
-     __asm__ volatile ("rdtsc" : "=a" (a), "=d" (d));
-     return (d << 32) | a;
-}
-#endif
-
-__END_DECLS
-
-#endif /* __RDTSC_H__ */
-
-/* vi:set tabstop=4 expandtab shiftwidth=4: this line set vi mode */
diff --git a/task.c b/task.c
index e6ff7d8bca2418ccea085715d86872650ac944af..f62ad821cd30e5766530d603d58a4b102aae79a7 100644 (file)
--- a/task.c
+++ b/task.c
 #include <unistd.h>
 
 #include "core.h"
-#include "rdtsc.h"
 #include "verbose.h"
 
 #include "task.h"
 
-long long tsc_start;
-
-void task_stat (task_t * t, int condensed)
-{
-    if (!t->is_sync) return;
-
-    pthread_mutex_lock(&t->stats_mutex);
-
-    if (condensed) {
-        VERBOSE (coretools, INFO, PRINTF ("%s=[%lu]", t->name, (unsigned long) tsc2ms (t->current_exec_time)));
-    } else {
-        VERBOSE (coretools, INFO, PRINTF ("task %s prio=%d cpu=%s last run in %lu µs [count=%d overtimes=%lu overloads=%lu, min=%lu average=%lu max=%lu]\n",
-                t->name, t->priority, t->cpu_list,
-                (unsigned long) tsc2ms (t->current_exec_time), t->count, t->overtimes,
-                t->overloads, (unsigned long) tsc2ms (t->min_exec_time),
-                t->count ? (unsigned long) tsc2ms (t->cumul_exec_time / t->count) : 0,
-                (unsigned long) tsc2ms (t->max_exec_time)));
-    }
-
-    pthread_mutex_unlock(&t->stats_mutex);
-}
-
-void *task_sync_runner (void *param)
-{
-    sub_task_t *s = (sub_task_t *) param;
-    task_t *t = s->task;
-
-    cpu_setaffinity(t->cpu_list);
-
-    if (t->priority) {
-        enable_realtime (t->priority);
-    }
-    pthread_mutex_init (&s->condition_mutex, NULL);
-    pthread_cond_init (&s->condition_cond, NULL);
-
-    /* potential init function */
-    if (t->init) t->init (s, s->sub_task_id);
-    pthread_mutex_unlock (&t->init_mutex);
-
-    while (1) {
-        // Wait for the trigger
-        pthread_mutex_lock (&s->condition_mutex);
-        while (s->trigger == 0) {
-            pthread_cond_wait (&s->condition_cond, &s->condition_mutex);
-        }
-        pthread_mutex_unlock (&s->condition_mutex);
-
-        // Run the task and measure the execution time
-
-        long long tsc1, tsc2;
-
-        tsc1 = rdtsc ();
-        t->task (s, s->sub_task_id);
-        tsc2 = rdtsc ();
-
-        // Update performances indicators
-
-        pthread_mutex_lock (&t->stats_mutex);
-
-        t->current_exec_time = tsc2diff (tsc2, tsc1);
-        t->cumul_exec_time += t->current_exec_time;
-        t->count++;
-        s->count++;
-
-        if (s->start_time_us) *(s->start_time_us) = tsc2ms(tsc2diff (tsc1, tsc_start));
-        if (s->exec_time_us)  *(s->exec_time_us) = tsc2ms(t->current_exec_time);
-
-        if (t->current_exec_time > t->max_exec_time)
-            t->max_exec_time = t->current_exec_time;
-        if (t->current_exec_time / 10 > t->min_exec_time)
-            t->min_exec_time = 0;       // To avoid min=0
-        if ((t->current_exec_time < t->min_exec_time) || (t->min_exec_time == 0))
-            t->min_exec_time = t->current_exec_time;
-
-        if (t->current_exec_time > t->max_allowed_time) {
-            VERBOSE (coretools, WARNING, PRINTF ("task %s[%d] too slow %luus\n", t->name, s->sub_task_id, (unsigned long) tsc2ms (t->current_exec_time)));
-            t->overtimes++;
-        }
-
-        if (s->count > 10 && t->current_exec_time > 10*t->max_allowed_time) {
-            char ascii_time[80];
-            time_t my_time = time(NULL);
-            strftime(ascii_time, sizeof(ascii_time), "%T", localtime(&my_time));
-            VERBOSE (coretools, ERROR, printf ("%s: task %s[%d], big overtime %luus\n", ascii_time, t->name, s->sub_task_id, (unsigned long) tsc2ms (t->current_exec_time)));
-        }
-
-        pthread_mutex_unlock (&t->stats_mutex);
-
-        pthread_mutex_lock (&s->condition_mutex);
-        s->trigger = 0;
-        pthread_cond_signal (&s->condition_cond);
-        pthread_mutex_unlock (&s->condition_mutex);
-    }
-
-    return NULL;
-}
-
-int task_trig (task_t * t)
-{
-    assert (t != NULL);
-    int i;
-    for (i=0; i<t->nb_sub_tasks; i++) {
-        sub_task_t *s = &t->sub_task_list[i];
-        pthread_mutex_lock (&s->condition_mutex);
-        while (s->trigger != 0) {
-            pthread_cond_wait (&s->condition_cond, &s->condition_mutex);
-        }
-        s->trigger = 1;
-        pthread_cond_signal (&s->condition_cond);
-        pthread_mutex_unlock (&s->condition_mutex);
-    }
-    return 0;
-}
-
-int task_end (task_t * t)
-{
-    assert (t != NULL);
-    int i;
-    for (i=0; i<t->nb_sub_tasks; i++) {
-        sub_task_t *s = &t->sub_task_list[i];
-        pthread_mutex_lock (&s->condition_mutex);
-        while (s->trigger != 0) {
-            pthread_cond_wait (&s->condition_cond, &s->condition_mutex);
-        }
-        pthread_mutex_unlock (&s->condition_mutex);
-    }
-    return 0;
-}
-
-int task_selective_run (task_t * t, int run_list[])
-{
-    assert (t != NULL);
-    int i;
-
-    // Start all selected sub-tasks
-
-    for (i=0; i<t->nb_sub_tasks; i++) {
-        if (!run_list[i]) continue;
-        sub_task_t *s = &t->sub_task_list[i];
-        pthread_mutex_lock (&s->condition_mutex);
-        while (s->trigger != 0) {
-            pthread_cond_wait (&s->condition_cond, &s->condition_mutex);
-        }
-        s->trigger = 1;
-        pthread_cond_signal (&s->condition_cond);
-        pthread_mutex_unlock (&s->condition_mutex);
-
-    }
-
-    // Wait end of all selected sub-tasks
-
-    for (i=0; i<t->nb_sub_tasks; i++) {
-        if (!run_list[i]) continue;
-        sub_task_t *s = &t->sub_task_list[i];
-        pthread_mutex_lock (&s->condition_mutex);
-        while (s->trigger != 0) {
-            pthread_cond_wait (&s->condition_cond, &s->condition_mutex);
-        }
-        pthread_mutex_unlock (&s->condition_mutex);
-    }
-
-    return 0;
-}
-
-int task_try_trig (task_t * t)
-{
-    assert (t != NULL);
-
-    int i;
-    int nb_running = 0;
-    for (i=0; i<t->nb_sub_tasks; i++) nb_running += t->sub_task_list[i].trigger ? 1 : 0;
-
-    if (nb_running != 0) {
-        t->overloads++;
-        return -1;
-    }
-
-    task_trig(t);
-
-    return 0;
-}
-
-task_t *create_sync_task (const char *name, int (*task) (sub_task_t *, int),
-                          float max_allowed_time_us, int (*init) (sub_task_t *, int),
-                          int priority, int nb_sub_tasks, const char *cpu_list)
-{
-    int i;
-
-    task_t *t = calloc (1, sizeof (*t));
-    assert (t);
-
-    t->name = strdup (name);
-    t->is_sync = 1;
-    t->task = task;
-    t->max_allowed_time = (long long) (max_allowed_time_us / tsc2ms (1));
-    t->init = init;
-    t->priority = priority;
-    if (cpu_list) {
-        t->cpu_list = strdup(cpu_list);
-        for (i = 0; t->cpu_list[i] != 0; i++) {
-            if (t->cpu_list[i] == ':') {
-                t->cpu_list[i] = 0;
-                int nb = atoi (t->cpu_list + i + 1);
-                if (nb > 0)
-                    nb_sub_tasks = nb;
-            }
-        }
-    }
-    pthread_mutex_init (&t->stats_mutex, NULL);
-    pthread_mutex_init (&t->init_mutex, NULL);
-
-    t->sub_task_list = calloc (nb_sub_tasks, sizeof (sub_task_t));
-    assert (t->sub_task_list);
-    t->nb_sub_tasks = nb_sub_tasks;
-
-    VERBOSE (coretools, INFO, PRINTF ("Creating task %s[%d] prio=%d cpu=%s ttl=%d\n", t->name, t->nb_sub_tasks, t->priority, t->cpu_list, (int)(max_allowed_time_us)));
-
-    pthread_attr_t tattr;
-    int ret = 0;
-
-    size_t size = 1024 * 1024;
-
-    /* initialized with default attributes */
-    ret |= pthread_attr_init (&tattr);
-
-    /* setting the size of the stack also */
-    ret |= pthread_attr_setstacksize (&tattr, size);
-
-    for (i=0; i<nb_sub_tasks; i++) {
-        t->sub_task_list[i].task = t;
-        t->sub_task_list[i].sub_task_id = i;
-        pthread_mutex_lock (&t->init_mutex);
-        pthread_create (&t->sub_task_list[i].thread, &tattr, task_sync_runner, &t->sub_task_list[i]);
-    }
-
-    return t;
-}
-
 void *task_async_runner (void *param)
 {
     sub_task_t *s = (sub_task_t *) param;
@@ -276,8 +37,6 @@ void *task_async_runner (void *param)
     if (t->priority) {
         enable_realtime (t->priority);
     }
-    pthread_mutex_init (&s->condition_mutex, NULL);
-    pthread_cond_init (&s->condition_cond, NULL);
 
     while (!t->task (s, s->sub_task_id)) { }
 
@@ -293,7 +52,6 @@ task_t *create_async_task (const char *name, int (*task) (sub_task_t *, int),
     assert (t);
 
     t->name = strdup (name);
-    t->is_sync = 0;
     t->task = task;
      t->priority = priority;
     if (cpu_list) {
diff --git a/task.h b/task.h
index e86f41464f9840865e5932e12ad77bc8830ed30f..142b66d58495a55b81e08bd55e279d88974f9266 100644 (file)
--- a/task.h
+++ b/task.h
@@ -23,22 +23,13 @@ struct _task_t;
 
 typedef struct {
     pthread_t thread;
-    pthread_mutex_t condition_mutex;
-    pthread_cond_t condition_cond;
-    int trigger;
     struct _task_t *task;
     int sub_task_id;
-
-    int count;
-
-    unsigned long *start_time_us;
-    unsigned long *exec_time_us;
 } sub_task_t;
 
 
 typedef struct _task_t {
     char *name;
-    int is_sync;
     int priority;
     char *cpu_list;
 
@@ -47,42 +38,11 @@ typedef struct _task_t {
 
     sub_task_t *sub_task_list;
     int nb_sub_tasks;
-
-    // Init function
-
-    int (*init) (sub_task_t *s, int subtask_id);
-    pthread_mutex_t init_mutex;
-
-    // Statistics section
-
-    pthread_mutex_t stats_mutex;
-
-    int count;
-    long long min_exec_time;
-    long long max_exec_time;
-    long long current_exec_time;
-    unsigned long long cumul_exec_time;
-    unsigned long int overtimes;
-    unsigned long int overloads;
 } task_t;
 
-task_t *create_sync_task (const char *name, int (*task) (sub_task_t *, int),
-                          float max_allowed_time_us, int (*init) (sub_task_t *, int),
-                          int priority, int nb_sub_tasks, const char *cpu_list);
-
 task_t *create_async_task (const char *name, int (*task) (sub_task_t *, int),
                            int priority, int nb_sub_tasks, const char *cpu_list);
 
-int task_trig (task_t * t);
-
-int task_try_trig (task_t * t);
-
-int task_end (task_t * t);
-
-int task_selective_run (task_t * t, int run_list[]);
-
-void task_stat (task_t * t, int condensed);
-
 void kill_all_subtasks (task_t *t, int sig);
 
 #endif /* __TASK_H__ */