psos: add tunables to configure region 0
PATCH v2 1/1 psos: add tunables to configure region 0
In the pSOS interface region 0 can be used by applications to allocate memory from. It contains 'system' memory and is created by default during system init. Region 0 is currently not supported by the xenomai psos skin.
This patch adds functionality to configure the total size and the unit size by means of following tunabels:
set_config_tunable(region0_size, 128000); set_config_tunable(region0_unitsize, 256);
The corresponding command-line options are:
psos-rn0-size
psos-rn0-unitsize
include/psos/tunables.h +22 -0
@@ -31,6 +31,8 @@ extern "C" {#endif /* __cplusplus */ extern int psos_long_names; +extern unsigned long psos_region0_size; +extern unsigned long psos_region0_unitsize; static inline define_config_tunable(long_names, int, on) {
@@ -42,6 +44,26 @@ static inline read_config_tunable(long_nreturn psos_long_names; } +static inline define_config_tunable(region0_size, unsigned long, size) +{ + psos_region0_size = size; +} + +static inline read_config_tunable(region0_size, unsigned long) +{ +return psos_region0_size; +} + +static inline define_config_tunable(region0_unitsize, unsigned long, size) +{ + psos_region0_unitsize = size; +} + +static inline read_config_tunable(region0_unitsize, unsigned long) +{ +return psos_region0_unitsize; +} +#ifdef __cplusplus }#endif /* __cplusplus */
lib/psos/init.c +32 -0
@@ -47,6 +47,8 @@* - Partitions, Regions, Timers */ int psos_long_names =0 ; +u_long psos_region0_size; +u_long psos_region0_unitsize;static unsigned int clock_resolution =1000000 ;/* 1ms */
@@ -70,6 +72,16 @@ static const struct option psos_options[ .flag = &psos_long_names, .val = 1 }, + { +#define region0_size_opt 3 + .name = "psos-rn0-size", + .has_arg = required_argument, + }, + { +#define region0_unitsize_opt 4 + .name = "psos-rn0-unitsize", + .has_arg = required_argument, + }, {/* Sentinel */ } };
@@ -82,6 +94,12 @@ static int psos_parse_option(int optnum,case time_slice_opt: time_slice_in_ticks =atoi (optarg);break ; +case region0_size_opt: + psos_region0_size = (u_long )atol (optarg); +break ; +case region0_unitsize_opt: + psos_region0_unitsize = (u_long )atol (optarg); +break ;case long_names_opt:break ;default :
@@ -96,6 +114,8 @@ static void psos_help(void) {fprintf (stderr,"--psos-clock-resolution=<ns> tick value (default 1ms)\n" );fprintf (stderr,"--psos-time-slice=<psos-ticks> round-robin time slice\n" ); +fprintf (stderr,"--psos-rn0-size=<size> region0 size in bytes\n" ); +fprintf (stderr,"--psos-rn0-unitsize=<usize> region0 unit size in bytes (default 128 bytes)\n" );fprintf (stderr,"--psos-long-names enable long names for objects (> 4 characters)\n" ); }
@@ -124,6 +144,18 @@ static int psos_init(void)return __bt (ret); } +if (psos_region0_size) { +u_long rsize; + ret =rn_create ("_RN0" ,xnmalloc (psos_region0_size), psos_region0_size, + (psos_region0_unitsize?psos_region0_unitsize:128 ),0 , &psos_region0_id, &rsize); +if (ret) { +warning ("%s: failed to initialize pSOS region 0 (ret=%u)" , + __FUNCTION__, ret); +return __bt (ret); + } + } + +/* Convert pSOS ticks to timespec. */ clockobj_ticks_to_timespec (&psos_clock, time_slice_in_ticks, &psos_rrperiod);
lib/psos/rn.c +8 -1
@@ -35,9 +35,16 @@ struct pvcluster psos_rn_table;static unsigned long anon_rnids; +u_long psos_region0_id =0 ; +static struct psos_rn *get_rn_from_id (u_long rnid,int *err_r) { - struct psos_rn *rn = mainheap_deref(rnid, struct psos_rn); +struct psos_rn *rn; + +if (rnid ==0 ) + rnid = psos_region0_id; + + rn = mainheap_deref(rnid, struct psos_rn);if (rn ==NULL || ((uintptr_t )rn & (sizeof (uintptr_t )-1 )) !=0 ) goto objid_error;
lib/psos/rn.h +1 -0
@@ -45,5 +45,6 @@ struct psos_rn_wait { };extern struct pvcluster psos_rn_table; +extern u_long psos_region0_id;#endif /* _PSOS_RN_H */
lib/psos/init.c static int psos_parse_option(int optnum, · line 102
Quoted 6 lines · Ronny Meeus
lib/psos/init.c +6
-0+case region0_size_opt: + psos_region0_size = (u_long )atol (optarg); +break ; +case region0_unitsize_opt: + psos_region0_unitsize = (u_long )atol (optarg); +break ;
You may want to sanitize the input values.
lib/psos/init.c static int psos_init(void) · line 149
Quoted 3 lines
lib/psos/init.c +3
-0+if (psos_region0_size) { +u_long rsize; + ret = rn_create("_RN0", xnmalloc(psos_region0_size), psos_region0_size,
If the value passed to --psos-rn0-size is larger than the memory available from the main heap, rn_create() will crash on a NULL return from xnmalloc().
Signature · 1 line
Philippe.