26
26
#include <sched.h>
27
27
#include <fcntl.h>
28
28
#include <sys/vfs.h>
29
+ #include <unistd.h>
30
+ #include <errno.h>
29
31
30
32
#define INTEL_RDT_MOUNT_POINT "/sys/fs/resctrl"
31
33
#define SCHEMATA_FILE "schemata"
@@ -45,10 +47,21 @@ is_rdt_mounted (libcrun_error_t *err)
45
47
return sfs .f_type == RDTGROUP_SUPER_MAGIC ;
46
48
}
47
49
48
- static int
49
- get_rdt_value (char * * out , const char * l3_cache_schema , const char * mem_bw_schema )
50
+ int
51
+ get_rdt_value (char * * out , const char * l3_cache_schema , const char * mem_bw_schema , char * const * schemata )
50
52
{
51
- return xasprintf (out , "%s%s%s\n" , l3_cache_schema ?: "" , (l3_cache_schema && mem_bw_schema ) ? "\n" : "" , mem_bw_schema ?: "" );
53
+ cleanup_free char * schemata_joined = NULL ;
54
+ size_t schemata_size = 0 ;
55
+
56
+ while (schemata && schemata [schemata_size ])
57
+ schemata_size ++ ;
58
+
59
+ if (schemata_size > 0 )
60
+ schemata_joined = str_join_array (0 , schemata_size , schemata , "\n" );
61
+
62
+ return xasprintf (out , "%s%s%s%s%s\n" , l3_cache_schema ?: "" ,
63
+ (l3_cache_schema && mem_bw_schema ) ? "\n" : "" , mem_bw_schema ?: "" ,
64
+ ((l3_cache_schema || mem_bw_schema ) && schemata_joined ) ? "\n" : "" , schemata_joined ?: "" );
52
65
}
53
66
54
67
struct key_value
@@ -189,12 +202,12 @@ validate_rdt_configuration (const char *name, const char *l3_cache_schema, const
189
202
}
190
203
191
204
static int
192
- write_intelrdt_string (int fd , const char * file , const char * l3_cache_schema , const char * mem_bw_schema , libcrun_error_t * err )
205
+ write_intelrdt_string (int fd , const char * file , const char * l3_cache_schema , const char * mem_bw_schema , char * const * schemata , libcrun_error_t * err )
193
206
{
194
207
cleanup_free char * formatted = NULL ;
195
208
int len , ret ;
196
209
197
- len = get_rdt_value (& formatted , l3_cache_schema , mem_bw_schema );
210
+ len = get_rdt_value (& formatted , l3_cache_schema , mem_bw_schema , schemata );
198
211
if (len < 0 )
199
212
return crun_make_error (err , errno , "internal error get_rdt_value" );
200
213
@@ -237,6 +250,8 @@ resctl_create (const char *name, bool explicit_clos_id, bool *created, const cha
237
250
int exist ;
238
251
int ret ;
239
252
253
+ * created = false;
254
+
240
255
ret = is_rdt_mounted (err );
241
256
if (UNLIKELY (ret < 0 ))
242
257
return ret ;
@@ -269,9 +284,12 @@ resctl_create (const char *name, bool explicit_clos_id, bool *created, const cha
269
284
return validate_rdt_configuration (name , l3_cache_schema , mem_bw_schema , err );
270
285
271
286
/* At this point, assume it was created. */
287
+ ret = crun_ensure_directory (path , 0755 , true, err );
288
+ if (UNLIKELY (ret < 0 ))
289
+ return ret ;
272
290
* created = true;
273
291
274
- return crun_ensure_directory ( path , 0755 , true, err ) ;
292
+ return 0 ;
275
293
}
276
294
277
295
int
@@ -292,33 +310,34 @@ resctl_move_task_to (const char *name, pid_t pid, libcrun_error_t *err)
292
310
}
293
311
294
312
int
295
- resctl_update (const char * name , const char * l3_cache_schema , const char * mem_bw_schema , libcrun_error_t * err )
313
+ resctl_update (const char * name , const char * l3_cache_schema , const char * mem_bw_schema ,
314
+ char * const * schemata , libcrun_error_t * err )
296
315
{
316
+ const char * actual_l3_cache_schema = l3_cache_schema ;
297
317
cleanup_free char * cleaned_l3_cache_schema = NULL ;
298
318
cleanup_free char * path = NULL ;
299
319
cleanup_close int fd = -1 ;
300
320
int ret ;
301
321
302
322
/* Nothing to do. */
303
- if (l3_cache_schema == NULL && mem_bw_schema == NULL )
323
+ if (l3_cache_schema == NULL && mem_bw_schema == NULL && schemata == NULL )
304
324
return 0 ;
305
325
306
326
ret = append_paths (& path , err , INTEL_RDT_MOUNT_POINT , name , SCHEMATA_FILE , NULL );
307
327
if (UNLIKELY (ret < 0 ))
308
328
return ret ;
309
329
310
330
if (l3_cache_schema && strstr (l3_cache_schema , "MB:" ))
311
- l3_cache_schema = cleaned_l3_cache_schema = intelrdt_clean_l3_cache_schema (l3_cache_schema );
331
+ {
332
+ cleaned_l3_cache_schema = intelrdt_clean_l3_cache_schema (l3_cache_schema );
333
+ actual_l3_cache_schema = cleaned_l3_cache_schema ;
334
+ }
312
335
313
336
fd = open (path , O_WRONLY | O_CLOEXEC );
314
337
if (UNLIKELY (fd < 0 ))
315
- return crun_make_error (err , errno , "open `%s`" , path );
338
+ return crun_make_error (err , errno , "open `%s` for writing " , path );
316
339
317
- ret = write_intelrdt_string (fd , path , l3_cache_schema , mem_bw_schema , err );
318
- if (UNLIKELY (ret < 0 ))
319
- return ret ;
320
-
321
- return 0 ;
340
+ return write_intelrdt_string (fd , path , actual_l3_cache_schema , mem_bw_schema , schemata , err );
322
341
}
323
342
324
343
int
0 commit comments