Skip to contentSkip to conversation

psos: add interface to configure region 0

PATCH In review Ronny Meeus 2 participants 4 messages Nov 30, 2016 – Dec 3, 2016

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 psos: add interface 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 a 'pseudo 0' region that will be used if applications allocate memory from region 0.

To enable this, following code needs to be added to the early application init code to configure region 0 (before applications use rn_getseg(0,...)).

unsigned long rnid,rsize;
unsigned long rn_0_size = 128000;
unsigned long unit_size = 128;

rn_create("_RN0",malloc(rn_0_size),rn_0_size, unit_size, 0, &rnid, &rsize); set_pseudo_rn0_id(rnid);

include/psos/psos.h +2 -0
@@ -253,6 +253,8 @@ u_long q_vbroadcast(u_long qid,
 		    u_long msglen,
 		    u_long *count_r);
 
+void set_pseudo_rn0_id(unsigned long id);
+
 u_long rn_create(const char *name,
 		 void *saddr,
 		 u_long rnsize,
lib/psos/rn.c +12 -0
@@ -35,6 +35,12 @@ struct pvcluster psos_rn_table;
 
 static unsigned long anon_rnids;
 
+static unsigned long pseudo_rn0_id = 0;
+void set_pseudo_rn0_id(unsigned long id)
+{
+  pseudo_rn0_id = id;
+}
+
 static struct psos_rn *get_rn_from_id(u_long rnid, int *err_r)
 {
 	struct psos_rn *rn = mainheap_deref(rnid, struct psos_rn);
@@ -226,6 +232,9 @@ u_long rn_getseg(u_long rnid, u_long siz
 	int ret = SUCCESS;
 	void *seg;
 
+	if (rnid == 0)
+		rnid = pseudo_rn0_id;
+
 	rn = get_rn_from_id(rnid, &ret);
 	if (rn == NULL)
 		return ret;
@@ -303,6 +312,9 @@ u_long rn_retseg(u_long rnid, void *sega
 	u_long size;
 	void *seg;
 
+	if (rnid == 0)
+		rnid = pseudo_rn0_id;
+
 	rn = get_rn_from_id(rnid, &ret);
 	if (rn == NULL)
 		return ret;
#1 lore raw
Quoted 21 lines · Ronny Meeus

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 a 'pseudo 0' region that will be used if applications allocate memory from region 0.

To enable this, following code needs to be added to the early application init code to configure region 0 (before applications use rn_getseg(0,...)).

unsigned long rnid,rsize;
unsigned long rn_0_size = 128000;
unsigned long unit_size = 128;

rn_create("_RN0",malloc(rn_0_size),rn_0_size, unit_size, 0, &rnid, &rsize); set_pseudo_rn0_id(rnid);

include/psos/psos.h u_long q_vbroadcast(u_long qid, · line 257

Quoted 5 lines
include/psos/psos.h +2 -0
@@ -253,6 +253,8 @@ u_long q_vbroadcast(u_long qid,
 		    u_long msglen,
 		    u_long *count_r);
 
+void set_pseudo_rn0_id(unsigned long id);
+

I'm fine with the reason to add support for RN#0, not with the way you do it. The proper logic would rather be:

- define proper tunable psos_rn0_size representing the size of RN#0, defaulting to 0 bytes
- create RN#0 from psos_init() if psos_rn0_size is non-zero

That would address several issues:

- eliminate the quite ugly remapping from 0 to some pseudo rnid
- keep the tunable bits in the emulator core (this stuff is no application's business in the Xenomai model).
- allow pulling memory from RN#0 from static C++ ctors and other library init code which may run before the application entry point is reached. i.e:
http://xenomai.org/2015/05/application-setup-and-init/#Initialization_sequence

The application would only have to call set_config_tunable(psos_rn0_size, <size>) from a setup() handler, as documented here (likewise for the unit size):

http://xenomai.org/2015/05/application-setup-and-init/#Overriding_factory_default_values_of_tunables

Signature · 1 line
Philippe.
#2 lore raw
Quoted 45 lines · Philippe Gerum
Quoted 21 lines · Ronny Meeus

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 a 'pseudo 0' region that will be used if applications allocate memory from region 0.

To enable this, following code needs to be added to the early application init code to configure region 0 (before applications use rn_getseg(0,...)).

unsigned long rnid,rsize;
unsigned long rn_0_size = 128000;
unsigned long unit_size = 128;

rn_create("_RN0",malloc(rn_0_size),rn_0_size, unit_size, 0, &rnid, &rsize); set_pseudo_rn0_id(rnid);

include/psos/psos.h u_long q_vbroadcast(u_long qid, · line 257

Quoted 5 lines
include/psos/psos.h +2 -0
@@ -253,6 +253,8 @@ u_long q_vbroadcast(u_long qid,
                  u_long msglen,
                  u_long *count_r);
 
+void set_pseudo_rn0_id(unsigned long id);
+

I'm fine with the reason to add support for RN#0, not with the way you do it. The proper logic would rather be:

- define proper tunable psos_rn0_size representing the size of RN#0, defaulting to 0 bytes
- create RN#0 from psos_init() if psos_rn0_size is non-zero

That would address several issues:

- eliminate the quite ugly remapping from 0 to some pseudo rnid
- keep the tunable bits in the emulator core (this stuff is no application's business in the Xenomai model).
- allow pulling memory from RN#0 from static C++ ctors and other library init code which may run before the application entry point is reached. i.e:
http://xenomai.org/2015/05/application-setup-and-init/#Initialization_sequence

Quoted 6 lines

The application would only have to call set_config_tunable(psos_rn0_size, <size>) from a setup() handler, as documented here (likewise for the unit size):

http://xenomai.org/2015/05/application-setup-and-init/#Overriding_factory_default_values_of_tunables

Philippe

disadvantage I see is that the memory allocation is not under control of the application.
But we can live with it.

I will add implement the tunables mechanism and provide a new patch later.

Can I add it to the file psos/tunable.h added in the other patch I provided earlier?
See mail "[PATCH v2] psos.h: remove dependency on tunables.h" in other words, do you accept that change?

Thanks
Ronny

Quoted 2 lines

--
Philippe.

#3 lore raw
Quoted 50 lines · Ronny Meeus
Quoted 49 lines · Philippe Gerum
Quoted 21 lines · Ronny Meeus

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 a 'pseudo 0' region that will be used if applications allocate memory from region 0.

To enable this, following code needs to be added to the early application init code to configure region 0 (before applications use rn_getseg(0,...)).

unsigned long rnid,rsize;
unsigned long rn_0_size = 128000;
unsigned long unit_size = 128;

rn_create("_RN0",malloc(rn_0_size),rn_0_size, unit_size, 0, &rnid, &rsize); set_pseudo_rn0_id(rnid);

include/psos/psos.h u_long q_vbroadcast(u_long qid, · line 257

Quoted 5 lines
include/psos/psos.h +2 -0
@@ -253,6 +253,8 @@ u_long q_vbroadcast(u_long qid,
                  u_long msglen,
                  u_long *count_r);
 
+void set_pseudo_rn0_id(unsigned long id);
+

I'm fine with the reason to add support for RN#0, not with the way you do it. The proper logic would rather be:

- define proper tunable psos_rn0_size representing the size of RN#0, defaulting to 0 bytes
- create RN#0 from psos_init() if psos_rn0_size is non-zero

That would address several issues:

- eliminate the quite ugly remapping from 0 to some pseudo rnid
- keep the tunable bits in the emulator core (this stuff is no application's business in the Xenomai model).
- allow pulling memory from RN#0 from static C++ ctors and other library init code which may run before the application entry point is reached. i.e:
http://xenomai.org/2015/05/application-setup-and-init/#Initialization_sequence

The application would only have to call set_config_tunable(psos_rn0_size, <size>) from a setup() handler, as documented here (likewise for the unit size):

Quoted 8 lines
Quoted 2 lines

http://xenomai.org/2015/05/application-setup-and-init/#Overriding_factory_default_values_of_tunables

Philippe

disadvantage I see is that the memory allocation is not under control of the application.
But we can live with it.

Since the application can fully decide whether RN#0 gets instantiated, and how large it should be, I really don't see any restriction on memory management using the proper tunables would introduce.

RN#0 is special, it should be addressable from early code, which is out of the application's scope and knowledge. So in this case, the Xenomai libs know better.

Quoted 5 lines

I will add implement the tunables mechanism and provide a new patch later.

Can I add it to the file psos/tunable.h added in the other patch I provided earlier?

Yes, that would make sense.

Quoted 3 lines

See mail "[PATCH v2] psos.h: remove dependency on tunables.h" in other words, do you accept that change?

Yes, that looks ok.

Signature · 1 line
Philippe.