32
32
#define INTEL_RDT_MOUNT_POINT "/sys/fs/resctrl"
33
33
#define SCHEMATA_FILE "schemata"
34
34
#define TASKS_FILE "tasks"
35
+ #define MON_GROUPS "mon_groups"
35
36
#define RDTGROUP_SUPER_MAGIC 0x7655821
36
37
37
38
static int
@@ -243,7 +244,7 @@ intelrdt_clean_l3_cache_schema (const char *l3_cache_schema)
243
244
}
244
245
245
246
int
246
- resctl_create (const char * name , bool explicit_clos_id , bool * created , const char * l3_cache_schema , const char * mem_bw_schema , libcrun_error_t * err )
247
+ resctl_create (const char * name , bool explicit_clos_id , bool * created , const char * l3_cache_schema , const char * mem_bw_schema , char * const * schemata , libcrun_error_t * err )
247
248
{
248
249
cleanup_free char * cleaned_l3_cache_schema = NULL ;
249
250
cleanup_free char * path = NULL ;
@@ -269,9 +270,9 @@ resctl_create (const char *name, bool explicit_clos_id, bool *created, const cha
269
270
if (l3_cache_schema && strstr (l3_cache_schema , "MB:" ))
270
271
l3_cache_schema = cleaned_l3_cache_schema = intelrdt_clean_l3_cache_schema (l3_cache_schema );
271
272
272
- /* If the closID was specified and both l3cache and bwSchema are unset, the group
273
- must exist. */
274
- if (explicit_clos_id && l3_cache_schema == NULL && mem_bw_schema == NULL )
273
+ /* If the closID was specified and both l3cache and bwSchema are unset, and schemata is empty,
274
+ the group must exist. */
275
+ if (explicit_clos_id && is_empty_string ( l3_cache_schema ) && is_empty_string ( mem_bw_schema ) && ( schemata == NULL ) )
275
276
{
276
277
if (exist )
277
278
return 0 ;
@@ -293,8 +294,9 @@ resctl_create (const char *name, bool explicit_clos_id, bool *created, const cha
293
294
}
294
295
295
296
int
296
- resctl_move_task_to (const char * name , pid_t pid , libcrun_error_t * err )
297
+ resctl_move_task_to (const char * name , const char * monitoring_name , pid_t pid , libcrun_error_t * err )
297
298
{
299
+ cleanup_free char * monitoring_path = NULL ;
298
300
cleanup_free char * path = NULL ;
299
301
char pid_str [32 ];
300
302
int len ;
@@ -308,7 +310,22 @@ resctl_move_task_to (const char *name, pid_t pid, libcrun_error_t *err)
308
310
if (UNLIKELY (len >= (int ) sizeof (pid_str )))
309
311
return crun_make_error (err , 0 , "internal error: static buffer too small" );
310
312
311
- return write_file (path , pid_str , len , err );
313
+ ret = write_file (path , pid_str , len , err );
314
+ if (UNLIKELY (ret < 0 ))
315
+ return ret ;
316
+
317
+ if (monitoring_name )
318
+ {
319
+ ret = append_paths (& monitoring_path , err , INTEL_RDT_MOUNT_POINT , name , MON_GROUPS , monitoring_name , TASKS_FILE , NULL );
320
+ if (UNLIKELY (ret < 0 ))
321
+ return ret ;
322
+
323
+ ret = write_file (monitoring_path , pid_str , len , err );
324
+ if (UNLIKELY (ret < 0 ))
325
+ return ret ;
326
+ }
327
+
328
+ return 0 ;
312
329
}
313
330
314
331
int
@@ -342,6 +359,35 @@ resctl_update (const char *name, const char *l3_cache_schema, const char *mem_bw
342
359
return write_intelrdt_string (fd , path , actual_l3_cache_schema , mem_bw_schema , schemata , err );
343
360
}
344
361
362
+ static int
363
+ resctl_get_monitoring_path (const char * resctrl_group_name , const char * container_id , char * * monitoring_path , libcrun_error_t * err )
364
+ {
365
+ int ret ;
366
+
367
+ ret = append_paths (monitoring_path , err , INTEL_RDT_MOUNT_POINT , resctrl_group_name , MON_GROUPS , container_id , NULL );
368
+ if (UNLIKELY (ret < 0 ))
369
+ return ret ;
370
+
371
+ return 0 ;
372
+ }
373
+
374
+ int
375
+ resctl_destroy_monitoring_group (const char * resctrl_group_name , const char * container_id , libcrun_error_t * err )
376
+ {
377
+ cleanup_free char * monitoring_path = NULL ;
378
+ int ret ;
379
+
380
+ ret = resctl_get_monitoring_path (resctrl_group_name , container_id , & monitoring_path , err );
381
+ if (UNLIKELY (ret < 0 ))
382
+ return ret ;
383
+
384
+ ret = rmdir (monitoring_path );
385
+ if (UNLIKELY (ret < 0 && errno != ENOENT ))
386
+ return crun_make_error (err , errno , "rmdir `%s`" , monitoring_path );
387
+
388
+ return 0 ;
389
+ }
390
+
345
391
int
346
392
resctl_destroy (const char * name , libcrun_error_t * err )
347
393
{
@@ -353,8 +399,25 @@ resctl_destroy (const char *name, libcrun_error_t *err)
353
399
return ret ;
354
400
355
401
ret = rmdir (path );
356
- if (UNLIKELY (ret < 0 ))
402
+ if (UNLIKELY (ret < 0 && errno != ENOENT ))
357
403
return crun_make_error (err , errno , "rmdir `%s`" , path );
358
404
359
405
return 0 ;
360
406
}
407
+
408
+ int
409
+ resctl_create_monitoring_group (const char * resctrl_group_name , const char * container_id , libcrun_error_t * err )
410
+ {
411
+ cleanup_free char * monitoring_path = NULL ;
412
+ int ret ;
413
+
414
+ ret = resctl_get_monitoring_path (resctrl_group_name , container_id , & monitoring_path , err );
415
+ if (UNLIKELY (ret < 0 ))
416
+ return ret ;
417
+
418
+ ret = crun_ensure_directory (monitoring_path , 0755 , true, err );
419
+ if (UNLIKELY (ret < 0 ))
420
+ return ret ;
421
+
422
+ return 0 ;
423
+ }
0 commit comments