Project

General

Profile

Pull request #218 » codel_rusage.patch

Félix Ingrand, 2019-10-02 10:15

View differences:

client/c/client.c
1 1
<'
2
# Copyright (c) 2012-2014,2017-2019 LAAS/CNRS
2
# Copyright (c) 2012-2019 LAAS/CNRS
3 3
# All rights reserved.
4 4
#
5 5
# Redistribution and use  in source  and binary  forms,  with or without
client/c/init.c
1 1
<'
2
# Copyright (c) 2012-2017,2019 LAAS/CNRS
2
# Copyright (c) 2012-2019 LAAS/CNRS
3 3
# All rights reserved.
4 4
#
5 5
# Redistribution and use  in source  and binary  forms,  with or without
client/c/msglib.c
1 1
<'
2
# Copyright (c) 2012-2013,2017-2018 LAAS/CNRS
2
# Copyright (c) 2012-2019 LAAS/CNRS
3 3
# All rights reserved.
4 4
#
5 5
# Redistribution and use  in source  and binary  forms,  with or without
client/c/pocolibs-client.c
1 1
/*
2
 * Copyright (c) 2012-2014,2016-2019 LAAS/CNRS
2
 * Copyright (c) 2012-2019 LAAS/CNRS
3 3
 * All rights reserved.
4 4
 *
5 5
 * Redistribution and use  in source  and binary  forms,  with or without
server/control_codels.c
232 232
    }
233 233
    lappend plist &self->control.context
234 234
'>
235
  s = <"[$validate invoke $plist]">;
235
  call_codel_with_timelog(<"[$validate name]">_ru, s = <"[$validate invoke $plist]">);
236 236
  genom_give_resource(self, self->resources.control = NULL);
237 237

  
238 238
  genom_log_debug("service <"[$s name]"> validation returned %s", s?s:"ok");
......
306 306
    }
307 307
    lappend plist &self->control.context
308 308
'>
309
  s = <"[$c invoke $plist]">;
309
   call_codel_with_timelog(<"[$c name]">_ru, s = <"[$c invoke $plist]">);
310 310
  genom_give_resource(self, self->resources.control = NULL);
311 311

  
312 312
  genom_log_debug("service %s codel %s returned %s",
server/control_task.c
1 1
<'
2
# Copyright (c) 2011-2017,2019 LAAS/CNRS
2
# Copyright (c) 2011-2019 LAAS/CNRS
3 3
# All rights reserved.
4 4
#
5 5
# Redistribution and use  in source  and binary  forms,  with or without
......
56 56
static void	<"$comp">_<"[$s name]">_rqstcb(SERV_ID csserv, int sid);
57 57
<'}'>
58 58
static void *	<"$comp">_cntrl_task(void *);
59

  
59
static void     report_codels_usage(struct codel_usage usage[]);
60
static void     report_nb_transitions(unsigned int nb_call[]);
60 61

  
61 62
/* <"[--- genom_${comp}_init --------------------------------------------]"> */
62 63

  
......
156 157
  pthread_mutex_init(&self->resources.lock, NULL);
157 158
  pthread_cond_init(&self->resources.sync, NULL);
158 159

  
160
  /* Initialise codels rusage struct and transition table*/
161
  {
162
    int i;
163
    for(i = 0; i < ncodel_max; i++) {
164
      self->codels_usage[i].calls = 0;
165
      self->codels_usage[i].min = 9999.;
166
      self->codels_usage[i].max = 0.;
167
      self->codels_usage[i].cum = 0.;
168
    }
169

  
170
    for(i = 0; i < n_trans_max; i++) {
171
      self->nb_trans_called[i] = 0;
172
    }
173

  
174
  }
175
  
159 176
  /* create posters */
160 177
  if (genom_metadata_<"$comp">_init(self)) goto error;
161 178
  if (genom_state_<"$comp">_init(self)) goto error;
......
331 348
    pthread_mutex_unlock(&self->control.lock);
332 349
  }
333 350

  
351
  report_codels_usage(self->codels_usage);
352
  report_nb_transitions(self->nb_trans_called);
353

  
334 354
  /* clean up */
335 355
<'foreach p [$component ports] {'>
336 356
  genom_<"$comp">_<"[$p name]">_delete(&self->control.context);
......
628 648

  
629 649
<'}'>
630 650

  
651
void report_nb_transitions(unsigned int nb_call[])
652
{
653
<'set tasks [$component tasks]'>
654
<'foreach task  $tasks {'>
655
<'foreach obj [list $task {*}[$task services]] {'>
656
<'  foreach state [$obj fsm] {'>
657
<'    foreach y [[$obj fsm $state] yield] {'>
658
    if (nb_call[<"[$obj name]">_<"[$state cname]">_<"[$y cname]">_st])
659
      genom_log_info("%u transitions for %s, from %s to %s.",
660
		     nb_call[<"[$obj name]">_<"[$state cname]">_<"[$y cname]">_st],
661
		     "<"[$obj name]">", "<"[$state cname]">", "<"[$y cname]">");
662
<'    }'>
663
<'  }'>
664
<'}'>
665
<'}'>
666
}
667

  
668

  
669
void report_codel_usage(char *name, struct codel_usage cu)
670
{
671
  if (cu.calls) {
672
    genom_log_info("%s called: %lu times, min: %f, max: %f, avg: %f.", name, cu.calls, cu.min, cu.max, cu.cum/cu.calls);
673
  } else {
674
    genom_log_info("%s not called once.", name);
675
  }
676
}
677

  
678
void report_codels_usage(struct codel_usage usage[]) {
679
<'
680
set tasks [$component tasks]
681
lappend tasks ""
682
foreach task  $tasks {
683
if {$task ne ""} {'>
684
<'  foreach codel [$task codels] {'>
685
<'  if {![catch {dict get $gcodels_for_report [$codel name]} prev]} {
686
      continue
687
    }
688
    dict set gcodels_for_report [$codel name] "task [$task name]"
689
'>
690
   report_codel_usage("<"[$codel name]">",usage[<"[$codel name]">_ru]);
691
<' } '>
692
<'}
693

  
694
if {$task eq ""} {
695
  foreach service [$component services] {
696
    if {[llength [$service validate]] == 0} continue'>
697
<'    foreach codel [$service validate] {'>
698
<'
699
      if {![catch {dict get $gcodels_for_report [$codel name]} prev]} {
700
        continue
701
      }
702
      dict set gcodels_for_report [$codel name] "service [$service name] validation"
703
'>
704
   report_codel_usage("<"[$codel name]">",usage[<"[$codel name]">_ru]);
705
<'       } '>
706
<'    } '>
707
<'}
708

  
709
foreach service [$component services] {
710
  if {[catch {$service task} t]} { set t "" }
711
  if {$t != $task || [llength [$service codels]] == 0} {
712
    continue
713
  } '>
714
<' foreach codel [$service codels] {'>
715
<'
716
   if {![catch {dict get $gcodels_for_report [$codel name]} prev]} {
717
     puts "\n/* already defined in $prev */"
718
     continue
719
   }
720
   dict set gcodels_for_report [$codel name] "service [$service name]"
721
'>
722
   report_codel_usage("<"[$codel name]">",usage[<"[$codel name]">_ru]);
723
<'    } '>
724
<' } '>
725
<'}'>
726
   printf("********* The wcet of the <"$comp"> codels are ***************\n");
727
<'foreach task  $tasks {
728
if {$task ne ""} {'>
729
<'  foreach codel [$task codels] {'>
730
<'  if {![catch {dict get $gcodels_for_wcet [$codel name]} prev]} {
731
      continue
732
    }
733
    dict set gcodels_for_wcet [$codel name] "task [$task name]"
734
'>
735
   if (usage[<"[$codel name]">_ru].calls)
736
     printf("<"$comp">_<"[$codel name]"> %f\n", usage[<"[$codel name]">_ru].max);
737
<' } '>
738
<'}
739

  
740
if {$task eq ""} {
741
  foreach service [$component services] {
742
    if {[llength [$service validate]] == 0} continue'>
743
<'    foreach codel [$service validate] {'>
744
<'
745
      if {![catch {dict get $gcodels_for_wcet [$codel name]} prev]} {
746
        continue
747
      }
748
      dict set gcodels_for_wcet [$codel name] "service [$service name] validation"
749
'>
750
   if (usage[<"[$codel name]">_ru].calls)
751
     printf("<"$comp">_<"[$codel name]"> %f\n", usage[<"[$codel name]">_ru].max);
752
<'       } '>
753
<'    } '>
754
<'}
755

  
756
foreach service [$component services] {
757
  if {[catch {$service task} t]} { set t "" }
758
  if {$t != $task || [llength [$service codels]] == 0} {
759
    continue
760
  } '>
761
<' foreach codel [$service codels] {'>
762
<'
763
   if {![catch {dict get $gcodels_for_wcet [$codel name]} prev]} {
764
     puts "\n/* already defined in $prev */"
765
     continue
766
   }
767
   dict set gcodels_for_wcet [$codel name] "service [$service name]"
768
'>
769
   if (usage[<"[$codel name]">_ru].calls)
770
     printf("<"$comp">_<"[$codel name]"> %f\n", usage[<"[$codel name]">_ru].max);
771
<'    } '>
772
<' } '>
773
<'} '>
774
   printf("*****************************************************\n");
775
}
776

  
631 777
/* eof */
server/control_task.h
1 1
<'
2
# Copyright (c) 2011-2015,2017 LAAS/CNRS
2
# Copyright (c) 2011-2019 LAAS/CNRS
3 3
# All rights reserved.
4 4
#
5 5
# Redistribution and use  in source  and binary  forms,  with or without
......
30 30
#include <assert.h>
31 31
#include <pthread.h>
32 32
#include <stdarg.h>
33
#include <sys/time.h>
33 34

  
34 35
#include "csLib.h"
35 36
#include "semLib.h"
......
43 44
#include "<"$comp">_activity.h"
44 45

  
45 46

  
47
/* --- an enum of all the codels defined ----------------------------------------------------- */
48

  
49
struct codel_usage {
50
  char *name;
51
  unsigned long calls;
52
  float max;
53
  float min;
54
  float cum;
55
};
56

  
57
enum {
58
<'
59
set tasks [$component tasks]
60
lappend tasks ""
61
foreach task  $tasks {
62
if {$task ne ""} {'>
63
<'  foreach codel [$task codels] {'>
64
<'  if {![catch {dict get $generated_codels [$codel name]} prev]} {
65
      continue
66
    }
67
    dict set generated_codels [$codel name] "task [$task name]"
68
'>
69
  <"[$codel name]">_ru,
70
<' } '>
71
<'}
72

  
73
if {$task eq ""} {
74
  foreach service [$component services] {
75
    if {[llength [$service validate]] == 0} continue'>
76
<'    foreach codel [$service validate] {'>
77
<'
78
      if {![catch {dict get $generated_codels [$codel name]} prev]} {
79
        continue
80
      }
81
      dict set generated_codels [$codel name] "service [$service name] validation"
82
'>
83
  <"[$codel name]">_ru,
84
<'       } '>
85
<'    } '>
86
<'}
87

  
88
foreach service [$component services] {
89
  if {[catch {$service task} t]} { set t "" }
90
  if {$t != $task || [llength [$service codels]] == 0} {
91
    continue
92
  } '>
93
<' foreach codel [$service codels] {'>
94
<'
95
   if {![catch {dict get $generated_codels [$codel name]} prev]} {
96
     continue
97
   }
98
   dict set generated_codels [$codel name] "service [$service name]"
99
'>
100
  <"[$codel name]">_ru,
101
<'    } '>
102
<' } '>
103
<'} '>
104
  ncodel_max
105
};
106

  
107
/* --- an enum of all the state transition possible------------------------------------------------ */
108

  
109
enum {
110
<'set tasks [$component tasks]'>
111
<'foreach task  $tasks {'>
112
<'foreach obj [list $task {*}[$task services]] {'>
113
<'  foreach state [$obj fsm] {'>
114
<'    foreach y [[$obj fsm $state] yield] {'>
115
   <"[$obj name]">_<"[$state cname]">_<"[$y cname]">_st,
116
<'    }'>
117
<'  }'>
118
<'}'>
119
<'}'>
120
  n_trans_max
121
};
122

  
46 123
/* --- internal state ------------------------------------------------------ */
47 124

  
48 125
extern const char *genom_instance;
......
124 201
    pthread_mutex_t lock;
125 202
    pthread_cond_t sync;
126 203
  } resources;
204

  
205
  struct codel_usage codels_usage[ncodel_max];
206
  unsigned int nb_trans_called[n_trans_max];
207

  
127 208
};
128 209

  
129 210
/* resource access */
......
146 227
    pthread_mutex_unlock(&self->resources.lock);                        \
147 228
  } while(0)
148 229

  
230
#define call_codel_with_timelog(codel,call) do{				\
231
    float last;								\
232
    struct timeval tvs, tve;						\
233
    struct codel_usage *usage = &(self->codels_usage[codel]);		\
234
    gettimeofday(&tvs, NULL);						\
235
    call;								\
236
    gettimeofday(&tve, NULL);						\
237
    usage->calls++;							\
238
    last = tve.tv_sec - tvs.tv_sec +					\
239
      (tve.tv_usec - tvs.tv_usec)*1e-6;					\
240
    if (last > usage->max) usage->max = last;				\
241
    if (last < usage->min) usage->min = last;				\
242
    usage->cum += last;							\
243
  } while (0)
149 244

  
150 245
/* control task */
151 246
void *	genom_<"$comp">_init(void);
server/exec_codels.c
100 100
    }
101 101
    lappend plist "&self->tasks.[$task name].context"
102 102
'>
103
  s = <"[$codel invoke $plist]">;
103
  call_codel_with_timelog(<"[$codel name]">_ru, s = <"[$codel invoke $plist]">);
104 104
  genom_give_resource(self, self->resources.task_<"[$task name]"> = NULL);
105 105

  
106 106
  return s;
......
126 126
<'    foreach y [[$obj fsm $state] yield] {'>
127 127
<'      if {"pause" in [$y kind]} continue'>
128 128
<'      if {"ether" eq [$y name]} continue'>
129
      s == <"[$y cname]"> ||
129
        (s == <"[$y cname]"> &&
130
	 ++(self->nb_trans_called[<"[$obj name]">_<"[$state cname]">_<"[$y cname]">_st])) ||
130 131
<'  }'>
131
      0) {
132
      a->state = s;
132
        0) {
133
        a->state = s;
133 134
      return ACT_RUN;
134 135
    }
135 136
    if (
136 137
<'    foreach y [[$obj fsm $state] yield] {'>
137 138
<'      if {"pause" in [$y kind]} { '>
138
      (s == <"[$y cname]"> && (s = <"$comp">_<"[$y name]">)) ||
139
        (s == <"[$y cname]"> &&
140
         ++(self->nb_trans_called[<"[$obj name]">_<"[$state cname]">_<"[$y cname]">_st]) &&
141
         (s = <"$comp">_<"[$y name]">)) ||
139 142
<'      }'>
140 143
<'    }'>
141
      0) {
144
        0) {
142 145
      a->state = s;
143 146
      a->pause = 1;
144 147
      return ACT_RUN;
......
146 149
    if (
147 150
<'    foreach y [[$obj fsm $state] yield] {'>
148 151
<'      if {"ether" eq [$y name]} {'>
149
      s == <"[$y cname]"> ||
152
        (s == <"[$y cname]"> &&
153
         ++(self->nb_trans_called[<"[$obj name]">_<"[$state cname]">_<"[$y cname]">_st])) ||
150 154
<'      }'>
151 155
<'    }'>
152
      0) {
156
        0) {
153 157
      a->state = <"$comp">_ether;
154 158
      return ACT_ETHER;
155 159
    }
server/msglib.c
1 1
<'
2
# Copyright (c) 2011-2013,2017-2018 LAAS/CNRS
2
# Copyright (c) 2011-2019 LAAS/CNRS
3 3
# All rights reserved.
4 4
#
5 5
# Redistribution and use  in source  and binary  forms,  with or without
    (1-1/1)