@@ -1257,7 +1257,7 @@ parse_global(struct json_object *global, rtapp_options_t *opts)
1257
1257
else if (!strcmp (tmp_str , "file" ))
1258
1258
opts -> logsize = -2 ;
1259
1259
else if (!strcmp (tmp_str , "auto" ))
1260
- opts -> logsize = -2 ; /* Automatic buffer size computation is not supported yet so we fall back on file system mode */
1260
+ opts -> logsize = -1 ;
1261
1261
log_debug ("Log buffer set to %s mode" , tmp_str );
1262
1262
1263
1263
/*
@@ -1333,6 +1333,32 @@ get_opts_from_json_object(struct json_object *root, rtapp_options_t *opts)
1333
1333
json_object_put (tasks );
1334
1334
log_info (PFX "Free json objects" );
1335
1335
1336
+ /*
1337
+ * In order to compute the log's buffer size is required to find the minimum
1338
+ * period among all periodic tasks, if there are some. Once the period has
1339
+ * been found it is possible to compute how many bytes are required for the
1340
+ * logging buffer of such task, which is the worst case scenario.
1341
+ */
1342
+ if (opts -> logsize == -1 ) {
1343
+ unsigned long min = __LONG_MAX__ ;
1344
+ // Find minimum period among all tasks
1345
+ for (size_t i = 0 ; i < opts -> num_tasks ; ++ i ) {
1346
+ unsigned long period = opts -> threads_data [i ].sched_data -> period ;
1347
+ min = (period < min ) ? period : min ;
1348
+ }
1349
+
1350
+ /* If there are not periodic task should be sufficent just one instance
1351
+ * of timing_point_t */
1352
+ if (!min )
1353
+ opts -> logsize = sizeof (timing_point_t );
1354
+ else {
1355
+ unsigned long instances = (unsigned long ) opts -> duration * 1000000000 / min ;
1356
+ unsigned long bytes = instances * sizeof (timing_point_t );
1357
+ opts -> logsize = bytes ;
1358
+ }
1359
+
1360
+ log_notice ("Log buffer size fixed to %fMB per threads" , (float ) opts -> logsize / (1 << 20 ));
1361
+ }
1336
1362
}
1337
1363
1338
1364
void
0 commit comments