support multi-pthread per core
Re: [PATCH v4 16/17] ring: add sched_yield to avoid spin forever
In reply to a message not in the archiveHi Olivier,
Quoted 99 lines
-----Original Message-----
From: dev [mailto:[email protected]] On Behalf Of Olivier MATZ
Sent: Friday, February 06, 2015 3:20 PM
To: Liang, Cunming; [email protected]
Subject: Re: [dpdk-dev] [PATCH v4 16/17] ring: addsched_yieldto avoid spin foreverHi,
Quoted 74 lines · Cunming Liang
Add a
sched_yield()syscall if the thread spins for too long, waiting other thread to finish its operations on the ring. That gives pre-empted thread a chance to proceed and finish with ring enqnue/dequeue operation.
The purpose is to reduce contention on the ring.Signed-off-by Cunming Liang <[email protected]>--- lib/librte_ring/rte_ring.h | 35 +++++++++++++++++++++++++++++------ 1 file changed, 29 insertions(+), 6 deletions(-)lib/librte_ring/rte_ring.h +22
-6@@ -126,6 +126,7 @@ struct rte_ring_debug_stats {#define RTE_RING_NAMESIZE 32/**< The maximum length of a ring name. */ #define RTE_RING_MZ_PREFIX "RG_" +#define RTE_RING_PAUSE_REP 0x100/**< yield after num of times pause. */ /** * An RTE ring structure. @@ -410,7 +411,7 @@ __rte_ring_mp_do_enqueue(struct rte_ring *r, void * const *obj_table,uint32_t cons_tail, free_entries;const unsigned max = n;int success; -unsigned i; +unsigned i, rep;uint32_t mask = r->prod.mask;int ret;@@ -468,8 +469,19 @@ __rte_ring_mp_do_enqueue(struct rte_ring *r, void * const *obj_table,* If there are other enqueues in progress that preceded us, * we need to wait for them to complete */ -while (unlikely (r->prod.tail != prod_head)) -rte_pause (); +do { +/* avoid spin too long waiting for other thread finish */ +for (rep =RTE_RING_PAUSE_REP ; + rep !=0 && r->prod.tail != prod_head; rep--) +rte_pause (); + +/* +* It gives pre-empted thread a chance to proceed and +* finish with ring enqnue operation. +*/ +if (rep ==0 ) +sched_yield (); + }while (rep ==0 ); r->prod.tail = prod_next;return ret;@@ -589,7 +601,7 @@ __rte_ring_mc_do_dequeue(struct rte_ring *r, void **obj_table,uint32_t cons_next, entries;const unsigned max = n;int success; -unsigned i; +unsigned i, rep;uint32_t mask = r->prod.mask;/* move cons.head atomically */ @@ -634,8 +646,19 @@ __rte_ring_mc_do_dequeue(struct rte_ring *r, void **obj_table,* If there are other dequeues in progress that preceded us, * we need to wait for them to complete */ -while (unlikely (r->cons.tail != cons_head)) -rte_pause (); + do { + /* avoid spin too long waiting for other thread finish */ + for (rep = RTE_RING_PAUSE_REP; + rep != 0 && r->cons.tail != cons_head; rep--) + rte_pause(); +lib/librte_ring/rte_ring.h __rte_ring_mc_do_dequeue(struct rte_ring *r, void **obj_table, · line 664
Quoted 10 lines
lib/librte_ring/rte_ring.h +7
-0+/* +* It gives pre-empted thread a chance to proceed and +* finish with ring denqnue operation. +*/ +if (rep ==0 ) +sched_yield (); + }while (rep ==0 );__RING_STAT_ADD (r, deq_success, n); r->cons.tail = cons_next;The ring library was designed with the assumption that the code is not preemptable. The code is lock-less but not wait-less. Actually, if the code is preempted at a bad moment, it can spin forever until it's unscheduled.
Quoted 7 lines
I wonder if adding a
sched_yield()may not penalize the current implementations that only use one pthread per core? Even if there is only one pthread in the scheduler queue for this CPU, calling the scheduler code may cost thousands of cycles.Also, where does this value "
RTE_RING_PAUSE_REP0x100" comes from? Why0x100is better than 42 or than 10000?
The idea was to have something few times bigger than actual number active cores in the system, to minimise chance of a sched_yield() being called for the case when we have one thread per physical core.
My thought was that having that many repeats would make such chance neglectable. Though, right now, I don't have any data to back it up.
Quoted 4 lines
I think it could be good to check if there is a performance impact with this change, especially where there is a lot of contention on the ring. If it has an impact, what about adding a compile or runtime option?
Good idea, probably we should make RTE_RING_PAUSE_REP configuration option and let say avoid emitting ' sched_yield();' at all, if RTE_RING_PAUSE_REP == 0.
Konstantin
Quoted 4 lines
Regards,
Olivier
A message that is not in the archive (sent off-list or not yet received): 2601191342CEEE43887BDE71AB977258213E461C-pww93C2UFcwu0RiL9chJVbfspsVTdybXVpNB7YpNyf8@public.gmane.org
Re: [PATCH v4 16/17] ring: add sched_yield to avoid spin forever
Hi Konstantin,
Quoted 19 lines · Konstantin
Quoted 5 lines
The ring library was designed with the assumption that the code is not preemptable. The code is lock-less but not wait-less. Actually, if the code is preempted at a bad moment, it can spin forever until it's unscheduled.
Quoted 7 lines
I wonder if adding a
sched_yield()may not penalize the current implementations that only use one pthread per core? Even if there is only one pthread in the scheduler queue for this CPU, calling the scheduler code may cost thousands of cycles.Also, where does this value "
RTE_RING_PAUSE_REP0x100" comes from? Why0x100is better than 42 or than 10000?The idea was to have something few times bigger than actual number active cores in the system, to minimise chance of a
sched_yield()being called for the case when we have one thread per physical core.
My thought was that having that many repeats would make such chance neglectable. Though, right now, I don't have any data to back it up.
Quoted 7 lines
Quoted 4 lines
I think it could be good to check if there is a performance impact with this change, especially where there is a lot of contention on the ring. If it has an impact, what about adding a compile or runtime option?
Good idea, probably we should make
RTE_RING_PAUSE_REPconfiguration option and let say avoid emitting 'sched_yield();' at all, ifRTE_RING_PAUSE_REP== 0.
Yes, it looks like a good compromise.
Olivier
PATCH v4 17/17 timer: add support to non-EAL thread
In reply to a message not in the archiveAllow to setup timers only for EAL (lcore) threads (__lcore_id < MAX_LCORE_ID). E.g. – dynamically created thread will be able to reset/stop timer for lcore thread, but it will be not allowed to setup timer for itself or another non-lcore thread. rte_timer_manage() for non-lcore thread would simply do nothing and return straightway.
--- lib/librte_timer/rte_timer.c | 40 +++++++++++++++++++++++++++++++--------- lib/librte_timer/rte_timer.h | 2 +- 2 files changed, 32 insertions(+), 10 deletions(-)
lib/librte_timer/rte_timer.c +31 -9
@@ -79,9 +79,10 @@ static struct priv_timer priv_timer[RTE_MAX_LCORE];/* when debug is enabled, store some statistics */ #ifdef RTE_LIBRTE_TIMER_DEBUG -#define __TIMER_STAT_ADD (name, n) do { \ - unsigned __lcore_id = rte_lcore_id(); \ - priv_timer[__lcore_id].stats.name += (n); \ +#define __TIMER_STAT_ADD (name, n) do { \ + unsigned __lcore_id = rte_lcore_id(); \ + if (__lcore_id < RTE_MAX_LCORE) \ + priv_timer[__lcore_id].stats.name += (n); \ } while(0)#else #define __TIMER_STAT_ADD (name, n) do {} while(0)
@@ -127,15 +128,26 @@ timer_set_config_state(struct rte_timer *tim,unsigned lcore_id; lcore_id =rte_lcore_id (); +if (lcore_id >=RTE_MAX_LCORE ) + lcore_id =LCORE_ID_ANY ;/* wait that the timer is in correct status before update, * and mark it as being configured */ while (success ==0 ) { prev_status.u32 = tim->status.u32; +/* +* prevent race condition of non-EAL threads +* to update the timer. When 'owner == LCORE_ID_ANY', +* it means updated by a non-EAL thread. +*/ +if (lcore_id == (unsigned )LCORE_ID_ANY && + (uint16_t )lcore_id == prev_status.owner) +return -1 ; +/* timer is running on another core, exit */ if (prev_status.state ==RTE_TIMER_RUNNING && - (unsigned )prev_status.owner != lcore_id) + prev_status.owner != (uint16_t )lcore_id)return -1 ;/* timer is being configured on another core */
@@ -366,9 +378,13 @@ __rte_timer_reset(struct rte_timer *tim, uint64_t expire,/* round robin for tim_lcore */ if (tim_lcore == (unsigned )LCORE_ID_ANY ) { - tim_lcore =rte_get_next_lcore (priv_timer[lcore_id].prev_lcore, -0 ,1 ); - priv_timer[lcore_id].prev_lcore = tim_lcore; +if (lcore_id <RTE_MAX_LCORE ) { + tim_lcore =rte_get_next_lcore ( + priv_timer[lcore_id].prev_lcore, +0 ,1 ); + priv_timer[lcore_id].prev_lcore = tim_lcore; + }else + tim_lcore =rte_get_next_lcore (LCORE_ID_ANY ,0 ,1 ); }/* wait that the timer is in correct status before update,
@@ -378,7 +394,8 @@ __rte_timer_reset(struct rte_timer *tim, uint64_t expire,return -1 ;__TIMER_STAT_ADD (reset,1 ); -if (prev_status.state ==RTE_TIMER_RUNNING ) { +if (prev_status.state ==RTE_TIMER_RUNNING && + lcore_id <RTE_MAX_LCORE ) { priv_timer[lcore_id].updated =1 ; }
@@ -455,7 +472,8 @@ rte_timer_stop(struct rte_timer *tim)return -1 ;__TIMER_STAT_ADD (stop,1 ); -if (prev_status.state ==RTE_TIMER_RUNNING ) { +if (prev_status.state ==RTE_TIMER_RUNNING && + lcore_id <RTE_MAX_LCORE ) { priv_timer[lcore_id].updated =1 ; }
@@ -499,6 +517,10 @@ void rte_timer_manage(void)uint64_t cur_time;int i, ret; +/* timer manager only runs on EAL thread */ +if (lcore_id >=RTE_MAX_LCORE ) +return ; +__TIMER_STAT_ADD (manage,1 );/* optimize for the case where per-cpu list is empty */ if (priv_timer[lcore_id].pending_head.sl_next[0 ] ==NULL )
lib/librte_timer/rte_timer.h +1 -1
@@ -76,7 +76,7 @@ extern "C" {#define RTE_TIMER_RUNNING 2/**< State: timer function is running. */ #define RTE_TIMER_CONFIG 3/**< State: timer is being configured. */ -#define RTE_TIMER_NO_OWNER -1/**< Timer has no owner. */ +#define RTE_TIMER_NO_OWNER -2/**< Timer has no owner. */ /** * Timer type: Periodic or single (one-shot).
Signature · 1 line
1.8.1.4
A message that is not in the archive (sent off-list or not yet received): 1422842559-13617-18-git-send-email-cunming.liang-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org
Re: [PATCH v4 17/17] timer: add support to non-EAL thread
Hi,
Quoted 30 lines · Cunming Liang
Allow to setup timers only for EAL (lcore) threads (
__lcore_id<MAX_LCORE_ID). E.g. – dynamically created thread will be able to reset/stop timer for lcore thread, but it will be not allowed to setup timer for itself or another non-lcore thread.rte_timer_manage()for non-lcore thread would simply do nothing and return straightway.Signed-off-by Cunming Liang <[email protected]>--- lib/librte_timer/rte_timer.c | 40 +++++++++++++++++++++++++++++++--------- lib/librte_timer/rte_timer.h | 2 +- 2 files changed, 32 insertions(+), 10 deletions(-)lib/librte_timer/rte_timer.c +4
-3@@ -79,9 +79,10 @@ static struct priv_timer priv_timer[RTE_MAX_LCORE];/* when debug is enabled, store some statistics */ #ifdef RTE_LIBRTE_TIMER_DEBUG -#define __TIMER_STAT_ADD (name, n) do { \ - unsigned __lcore_id = rte_lcore_id(); \ - priv_timer[__lcore_id].stats.name += (n); \ +#define __TIMER_STAT_ADD (name, n) do { \ + unsigned __lcore_id = rte_lcore_id(); \ + if (__lcore_id < RTE_MAX_LCORE) \ + priv_timer[__lcore_id].stats.name += (n); \ } while(0)#else #define __TIMER_STAT_ADD (name, n) do {} while(0)
lib/librte_timer/rte_timer.c timer_set_config_state(struct rte_timer *tim, · line 132
Quoted 5 lines
lib/librte_timer/rte_timer.c +2
-0@@ -127,15 +128,26 @@ timer_set_config_state(struct rte_timer *tim,unsigned lcore_id; lcore_id =rte_lcore_id (); +if (lcore_id >=RTE_MAX_LCORE ) + lcore_id =LCORE_ID_ANY ;
Is this still valid?
In my understanding, rte_lcore_id() was returning the core id or LCORE_ID_ANY if it's a non-EAL thread.
Quoted 5 lines
lib/librte_timer/rte_timer.c +0
-0/* wait that the timer is in correct status before update, * and mark it as being configured */ while (success ==0 ) { prev_status.u32 = tim->status.u32;
lib/librte_timer/rte_timer.c timer_set_config_state(struct rte_timer *tim, · line 147
Quoted 10 lines
lib/librte_timer/rte_timer.c +9
-0+/* +* prevent race condition of non-EAL threads +* to update the timer. When 'owner == LCORE_ID_ANY', +* it means updated by a non-EAL thread. +*/ +if (lcore_id == (unsigned )LCORE_ID_ANY && + (uint16_t )lcore_id == prev_status.owner) +return -1 ; +
Are you sure this is required?
I think prev_status.owner can be LCORE_ID_ANY only in config state, as a timer cannot be scheduled on a non-EAL thread. And there is already a test that returns -1 if state is CONFIG.
Quoted 8 lines
lib/librte_timer/rte_timer.c +1
-1/* timer is running on another core, exit */ if (prev_status.state ==RTE_TIMER_RUNNING && - (unsigned )prev_status.owner != lcore_id) + prev_status.owner != (uint16_t )lcore_id)return -1 ;/* timer is being configured on another core */
lib/librte_timer/rte_timer.c __rte_timer_reset(struct rte_timer *tim, uint64_t expire, · line 381
Quoted 7 lines
lib/librte_timer/rte_timer.c +1
-3@@ -366,9 +378,13 @@ __rte_timer_reset(struct rte_timer *tim, uint64_t expire,/* round robin for tim_lcore */ if (tim_lcore == (unsigned )LCORE_ID_ANY ) { - tim_lcore =rte_get_next_lcore (priv_timer[lcore_id].prev_lcore, -0 ,1 ); - priv_timer[lcore_id].prev_lcore = tim_lcore; +if (lcore_id <RTE_MAX_LCORE ) {
if (lcore_id != LCORE_ID_ANY) ?
lib/librte_timer/rte_timer.c __rte_timer_reset(struct rte_timer *tim, uint64_t expire, · line 387
Quoted 6 lines
lib/librte_timer/rte_timer.c +6
-0+ tim_lcore =rte_get_next_lcore ( + priv_timer[lcore_id].prev_lcore, +0 ,1 ); + priv_timer[lcore_id].prev_lcore = tim_lcore; + }else + tim_lcore =rte_get_next_lcore (LCORE_ID_ANY ,0 ,1 );
I think the following line:tim_lcore = rte_get_next_lcore(LCORE_ID_ANY, 0, 1); Will return the first enabled core.
Maybe using rte_get_master_lcore() is clearer?
lib/librte_timer/rte_timer.c __rte_timer_reset(struct rte_timer *tim, uint64_t expire, · line 398
Quoted 10 lines
lib/librte_timer/rte_timer.c +2
-1}/* wait that the timer is in correct status before update, @@ -378,7 +394,8 @@ __rte_timer_reset(struct rte_timer *tim, uint64_t expire,return -1 ;__TIMER_STAT_ADD (reset,1 ); -if (prev_status.state ==RTE_TIMER_RUNNING ) { +if (prev_status.state ==RTE_TIMER_RUNNING && + lcore_id <RTE_MAX_LCORE ) {
if (lcore_id != LCORE_ID_ANY) ?
lib/librte_timer/rte_timer.c rte_timer_stop(struct rte_timer *tim) · line 476
Quoted 10 lines
lib/librte_timer/rte_timer.c +2
-1priv_timer[lcore_id].updated =1 ; }@@ -455,7 +472,8 @@ rte_timer_stop(struct rte_timer *tim)return -1 ;__TIMER_STAT_ADD (stop,1 ); -if (prev_status.state ==RTE_TIMER_RUNNING ) { +if (prev_status.state ==RTE_TIMER_RUNNING && + lcore_id <RTE_MAX_LCORE ) {
if (lcore_id != LCORE_ID_ANY) ?
lib/librte_timer/rte_timer.c void rte_timer_manage(void) · line 523
Quoted 11 lines
lib/librte_timer/rte_timer.c +4
-0priv_timer[lcore_id].updated =1 ; }@@ -499,6 +517,10 @@ void rte_timer_manage(void)uint64_t cur_time;int i, ret; +/* timer manager only runs on EAL thread */ +if (lcore_id >=RTE_MAX_LCORE ) +return ; +
Maybe an assert is more visible here. Else, if someone calls rte_timer_manage() from a non-EAL core, it will just exit silently.
Maybe adding a comment in rte_timer.h saying that this function must be called from an EAL core would also help.
Regards,
Olivier
A message that is not in the archive (sent off-list or not yet received): [email protected]
Re: [PATCH v4 17/17] timer: add support to non-EAL thread
Quoted 47 lines
-----Original Message-----
From: Olivier MATZ [mailto:[email protected]]
Sent: Wednesday, February 11, 2015 1:45 AM
To: Liang, Cunming; [email protected]
Subject: Re: [dpdk-dev] [PATCH v4 17/17] timer: add support to non-EAL threadHi,
Quoted 1 line · Cunming Liang
Allow to setup timers only for EAL (lcore) threads (
__lcore_id<
MAX_LCORE_ID).Quoted 1 line
E.g. – dynamically created thread will be able to reset/stop timer for lcore
thread,
Quoted 2 lines
but it will be not allowed to setup timer for itself or another non-lcore thread.
rte_timer_manage()for non-lcore thread would simply do nothing and returnstraightway.
Quoted 4 lines
Signed-off-by Cunming Liang <[email protected]>--- lib/librte_timer/rte_timer.c | 40 +++++++++++++++++++++++++++++++---------
Quoted 24 lines
lib/librte_timer/rte_timer.h | 2 +- 2 files changed, 32 insertions(+), 10 deletions(-)lib/librte_timer/rte_timer.c +4
-3@@ -79,9 +79,10 @@ static struct priv_timer priv_timer[RTE_MAX_LCORE];/* when debug is enabled, store some statistics */ #ifdef RTE_LIBRTE_TIMER_DEBUG -#define __TIMER_STAT_ADD (name, n) do { \ - unsigned __lcore_id = rte_lcore_id(); \ - priv_timer[__lcore_id].stats.name += (n); \ +#define __TIMER_STAT_ADD (name, n) do { \ + unsigned __lcore_id = rte_lcore_id(); \ + if (__lcore_id < RTE_MAX_LCORE) \ + priv_timer[__lcore_id].stats.name += (n); \ } while(0)#else #define __TIMER_STAT_ADD (name, n) do {} while(0)@@ -127,15 +128,26 @@ timer_set_config_state(struct rte_timer *tim,unsigned lcore_id;
Quoted 7 lines
lib/librte_timer/rte_timer.c timer_set_config_state(struct rte_timer *tim, · line 132
Quoted 3 lines
lib/librte_timer/rte_timer.c +2
-0lcore_id =rte_lcore_id (); +if (lcore_id >=RTE_MAX_LCORE ) + lcore_id =LCORE_ID_ANY ;Is this still valid?
In my understanding,rte_lcore_id()was returning the core id orLCORE_ID_ANYif it's a non-EAL thread.
[LCM] It's a nice to have one, in case lcore_id got an invalid number. We can add a assert to replace these two line.
Quoted 19 lines
Quoted 6 lines
lib/librte_timer/rte_timer.c +0
-0/* wait that the timer is in correct status before update, * and mark it as being configured */ while (success ==0 ) { prev_status.u32 = tim->status.u32;lib/librte_timer/rte_timer.c timer_set_config_state(struct rte_timer *tim, · line 147
Quoted 10 lines
lib/librte_timer/rte_timer.c +9
-0+/* +* prevent race condition of non-EAL threads +* to update the timer. When 'owner == LCORE_ID_ANY', +* it means updated by a non-EAL thread. +*/ +if (lcore_id == (unsigned )LCORE_ID_ANY && + (uint16_t )lcore_id == prev_status.owner) +return -1 ; +Are you sure this is required?
Quoted 3 lines
I think prev_status.owner can be
LCORE_ID_ANYonly in config state, as a timer cannot be scheduled on a non-EAL thread. And there is already a test that returns -1 if state is CONFIG.
[LCM] Good point, whenever prev_status.owner == LCORE_ID_ANY, the prev_status.state must be RTE_TIMER_CONFIG. Make sense to me to remove the condition check.
Quoted 12 lines
lib/librte_timer/rte_timer.c __rte_timer_reset(struct rte_timer *tim, uint64_t
Quoted 10 lines
lib/librte_timer/rte_timer.c +1
-1/* timer is running on another core, exit */ if (prev_status.state ==RTE_TIMER_RUNNING && - (unsigned )prev_status.owner != lcore_id) + prev_status.owner != (uint16_t )lcore_id)return -1 ;/* timer is being configured on another core */ @@ -366,9 +378,13 @@ __rte_timer_reset(struct rte_timer *tim, uint64_texpire,
Quoted 1 line
Quoted 8 lines
lib/librte_timer/rte_timer.c __rte_timer_reset(struct rte_timer *tim, uint64_t expire, · line 381
Quoted 6 lines
/* round robin for tim_lcore */ if (tim_lcore == (unsigned)LCORE_ID_ANY) {lib/librte_timer/rte_timer.c +1
-3- tim_lcore =rte_get_next_lcore (priv_timer[lcore_id].prev_lcore, -0 ,1 ); - priv_timer[lcore_id].prev_lcore = tim_lcore; +if (lcore_id <RTE_MAX_LCORE ) {if (
lcore_id!=LCORE_ID_ANY) ?
[LCM] Accept.
Quoted 13 lines
lib/librte_timer/rte_timer.c __rte_timer_reset(struct rte_timer *tim, uint64_t expire, · line 387
Quoted 8 lines
lib/librte_timer/rte_timer.c +6
-0+ tim_lcore =rte_get_next_lcore ( + priv_timer[lcore_id].prev_lcore, +0 ,1 ); + priv_timer[lcore_id].prev_lcore = tim_lcore; + }else + tim_lcore =rte_get_next_lcore (LCORE_ID_ANY ,0 ,1 );I think the following line:
tim_lcore=rte_get_next_lcore(LCORE_ID_ANY, 0, 1); Will return the first enabled core.
Quoted 1 line
Maybe using
rte_get_master_lcore()is clearer?
[LCM] It doesn't expect must to be a master lcore.
Any available lcore is fine, so I think make sense to just use the first enabled core.
Quoted 48 lines
lib/librte_timer/rte_timer.c __rte_timer_reset(struct rte_timer *tim, uint64_t
Quoted 7 lines
}/* wait that the timer is in correct status before update,
lib/librte_timer/rte_timer.c +0
-0@@ -378,7 +394,8 @@ __rte_timer_reset(struct rte_timer *tim, uint64_texpire,
lib/librte_timer/rte_timer.c __rte_timer_reset(struct rte_timer *tim, uint64_t expire, · line 398
Quoted 6 lines
lib/librte_timer/rte_timer.c +2
-1return -1 ;__TIMER_STAT_ADD (reset,1 ); -if (prev_status.state ==RTE_TIMER_RUNNING ) { +if (prev_status.state ==RTE_TIMER_RUNNING && + lcore_id <RTE_MAX_LCORE ) {if (
lcore_id!=LCORE_ID_ANY) ?lib/librte_timer/rte_timer.c rte_timer_stop(struct rte_timer *tim) · line 476
Quoted 10 lines
lib/librte_timer/rte_timer.c +2
-1priv_timer[lcore_id].updated =1 ; }@@ -455,7 +472,8 @@ rte_timer_stop(struct rte_timer *tim)return -1 ;__TIMER_STAT_ADD (stop,1 ); -if (prev_status.state ==RTE_TIMER_RUNNING ) { +if (prev_status.state ==RTE_TIMER_RUNNING && + lcore_id <RTE_MAX_LCORE ) {if (
lcore_id!=LCORE_ID_ANY) ?lib/librte_timer/rte_timer.c void rte_timer_manage(void) · line 523
Quoted 11 lines
lib/librte_timer/rte_timer.c +4
-0priv_timer[lcore_id].updated =1 ; }@@ -499,6 +517,10 @@ void rte_timer_manage(void)uint64_t cur_time;int i, ret; +/* timer manager only runs on EAL thread */ +if (lcore_id >=RTE_MAX_LCORE ) +return ; +Maybe an assert is more visible here. Else, if someone calls
rte_timer_manage()from a non-EAL core, it will just exit silently.
Quoted 2 lines
Maybe adding a comment in
rte_timer.hsaying that this function must be called from an EAL core would also help.
[LCM] accept.
Quoted 5 lines
Regards,
Olivier
A message that is not in the archive (sent off-list or not yet received): D0158A423229094DA7ABF71CF2FA0DA3118D8B5B-E2R4CRU6q/[email protected]
Re: [PATCH v4 17/17] timer: add support to non-EAL thread
Hi,
Quoted 11 lines · Cunming
Quoted 11 lines
lib/librte_timer/rte_timer.c __rte_timer_reset(struct rte_timer *tim, uint64_t expire, · line 387
Quoted 6 lines
lib/librte_timer/rte_timer.c +6
-0+ tim_lcore =rte_get_next_lcore ( + priv_timer[lcore_id].prev_lcore, +0 ,1 ); + priv_timer[lcore_id].prev_lcore = tim_lcore; + }else + tim_lcore =rte_get_next_lcore (LCORE_ID_ANY ,0 ,1 );I think the following line:
tim_lcore=rte_get_next_lcore(LCORE_ID_ANY, 0, 1); Will return the first enabled core.
Quoted 3 lines
Quoted 1 line
Maybe using
rte_get_master_lcore()is clearer?[LCM] It doesn't expect must to be a master lcore.
Any available lcore is fine, so I think make sense to just use the first enabled core.
Yes I agree it does not need to be the master lcore, but until recently the definition of the master lcore was "the first enabled core".
I was thinking rte_get_master_lcore() is easier to understand that rte_get_next_lcore(LCORE_ID_ANY, 0, 1). If you still prefer to keep the second one, can you add a comment saying something like "non-EAL thread do not run rte_timer_manage(), so schedule the timer on the first enabled lcore"?
Thanks,
Olivier
A message that is not in the archive (sent off-list or not yet received): [email protected]
Re: [PATCH v4 17/17] timer: add support to non-EAL thread
Hi,
Quoted 25 lines
-----Original Message-----
From: Olivier MATZ [mailto:[email protected]]
Sent: Thursday, February 12, 2015 1:22 AM
To: Liang, Cunming; [email protected]
Subject: Re: [dpdk-dev] [PATCH v4 17/17] timer: add support to non-EAL threadHi,
Quoted 11 lines · Cunming
Quoted 11 lines
Review
Quoted 6 lines
(quoted diff) +6
-0+ tim_lcore = rte_get_next_lcore( + priv_timer[lcore_id].prev_lcore, + 0, 1); + priv_timer[lcore_id].prev_lcore = tim_lcore; + } else + tim_lcore = rte_get_next_lcore(LCORE_ID_ANY, 0, 1);I think the following line:
tim_lcore=rte_get_next_lcore(LCORE_ID_ANY, 0, 1); Will return the first enabled core.Quoted 3 lines
Quoted 1 line
Maybe using
rte_get_master_lcore()is clearer?[LCM] It doesn't expect must to be a master lcore.
Any available lcore is fine, so I think make sense to just use the first enabledcore.
Quoted 8 lines
Yes I agree it does not need to be the master lcore, but until recently the definition of the master lcore was "the first enabled core".
I was thinking
rte_get_master_lcore()is easier to understand thatrte_get_next_lcore(LCORE_ID_ANY, 0, 1). If you still prefer to keep the second one, can you add a comment saying something like "non-EAL thread do not runrte_timer_manage(), so schedule the timer on the first enabled lcore"?
[LCM] That makes sense, will add it. Thanks.
Quoted 3 lines
Thanks,
Olivier
Ananyev, Konstantin
Acked-by Konstantin AnanyevQuoted 80 lines
From: Liang, Cunming
Sent: Monday, February 02, 2015 2:02 AM
To: [email protected]
Cc: Ananyev, Konstantin; Liang, Cunming
Subject: [PATCH v4 00/17] support multi-pthread per corev4 changes:
new patch fixingstrnlen()invalid return in 32bit icc [03/17] update and add more comments onsched_yield()[16/17]v3 changes:
new patch addingsched_yield()inrte_ringto avoid long spin [16/17]v2 changes:
add '<number>-<number>' support for EAL option '--lcores' [02/17]The patch series contain the enhancements of EAL and fixes for libraries
to run multi-pthreads(either EAL or non-EAL thread) per physical core.
Two major changes list as below:
- Extend the core affinity of each EAL thread to 1:n.
Each lcore stands for a EAL thread rather than a logical core.
The change adds new EAL option to allow static lcore to cpuset assginment. Then a lcore(EAL thread) affinity to a cpuset, original 1:1 mapping is the special case.
- Fix the libraries to allow running on any non-EAL thread.
It fix the gaps running libraries in non-EAL thread(dynamic created by user). Each fix libraries take care the case ofrte_lcore_id()>=RTE_MAX_LCORE.Thanks a million for the comments from Konstantin, Bruce, Mirek and Stephen in RFC review.
*** BLURB HERE ***
Cunming Liang (17):
eal: add cpuset into per EAL threadlcore_config
eal: new eal option '--lcores' for cpu assignment
eal: fix wrongstrnlen()return value in 32bit icc
eal: add support parsingsocket_idfrom cpuset
eal: new TLS definition and API declaration
eal: addeal_common_thread.cfor common thread API
eal: addrte_gettid()to acquire unique system tid
eal: apply affinity of EAL thread by assigned cpuset
enic: fix re-define freebsd compile complain
malloc: fix the issue ofSOCKET_ID_ANY
log: fix the gap to support non-EAL thread
eal: set_lcore_idand_socket_idto (-1) by default
eal: fix recursive spinlock in non-EAL thraed
mempool: add support to non-EAL thread
ring: add support to non-EAL thread
ring: addsched_yieldto avoid spin forever
timer: add support to non-EAL threadlib/librte_eal/bsdapp/eal/Makefile | 1 + lib/librte_eal/bsdapp/eal/eal.c | 13 +- lib/librte_eal/bsdapp/eal/eal_lcore.c | 14 + lib/librte_eal/bsdapp/eal/eal_memory.c | 2 + lib/librte_eal/bsdapp/eal/eal_thread.c | 76 +++--- lib/librte_eal/common/eal_common_launch.c | 1 - lib/librte_eal/common/eal_common_log.c | 17 +- lib/librte_eal/common/eal_common_options.c | 302 ++++++++++++++++++++- lib/librte_eal/common/eal_common_thread.c | 142 ++++++++++ lib/librte_eal/common/eal_options.h | 2 + lib/librte_eal/common/eal_thread.h | 66 +++++ .../common/include/generic/rte_spinlock.h | 4 +- lib/librte_eal/common/include/rte_eal.h | 27 ++ lib/librte_eal/common/include/rte_lcore.h | 37 ++- lib/librte_eal/common/include/rte_log.h | 5 + lib/librte_eal/linuxapp/eal/Makefile | 4 + lib/librte_eal/linuxapp/eal/eal.c | 7 +- lib/librte_eal/linuxapp/eal/eal_lcore.c | 15 + lib/librte_eal/linuxapp/eal/eal_thread.c | 78 +++--- lib/librte_malloc/malloc_heap.h | 7 +- lib/librte_mempool/rte_mempool.h | 18 +- lib/librte_pmd_enic/enic.h | 1 + lib/librte_pmd_enic/enic_compat.h | 1 + lib/librte_ring/rte_ring.h | 45 ++- lib/librte_timer/rte_timer.c | 40 ++- lib/librte_timer/rte_timer.h | 2 +- 26 files changed, 789 insertions(+), 138 deletions(-) create mode 100644 lib/librte_eal/common/eal_common_thread.c
Quoted 1 line
--
Quoted 1 line
1.8.1.4
Hi,
Quoted 10 lines · Cunming Liang
v4 changes:
new patch fixingstrnlen()invalid return in 32bit icc [03/17] update and add more comments onsched_yield()[16/17]v3 changes:
new patch addingsched_yield()inrte_ringto avoid long spin [16/17]v2 changes:
add '<number>-<number>' support for EAL option '--lcores' [02/17]
Quoted 10 lines
The patch series contain the enhancements of EAL and fixes for libraries
to run multi-pthreads(either EAL or non-EAL thread) per physical core.
Two major changes list as below:
- Extend the core affinity of each EAL thread to 1:n.
Each lcore stands for a EAL thread rather than a logical core.
The change adds new EAL option to allow static lcore to cpuset assginment. Then a lcore(EAL thread) affinity to a cpuset, original 1:1 mapping is the special case.
- Fix the libraries to allow running on any non-EAL thread.
It fix the gaps running libraries in non-EAL thread(dynamic created by user). Each fix libraries take care the case ofrte_lcore_id()>=RTE_MAX_LCORE.
Sorry if I missed something, but after reading the mailing list threads about this subject, I cannot find an explanation about what problem this series try to solve.
Can you give some details about which use-case require to have multiple pthreads per cpu? What are the advantage of doing so?
Regards,
Olivier
A message that is not in the archive (sent off-list or not yet received): [email protected]
Quoted 32 lines · Olivier MATZ
Hi,
Quoted 10 lines · Cunming Liang
v4 changes:
new patch fixingstrnlen()invalid return in 32bit icc [03/17] update and add more comments onsched_yield()[16/17]v3 changes:
new patch addingsched_yield()inrte_ringto avoid long spin [16/17]v2 changes:
add '<number>-<number>' support for EAL option '--lcores' [02/17]Quoted 6 lines
The patch series contain the enhancements of EAL and fixes for libraries to run multi-pthreads(either EAL or non-EAL thread) per physical core. Two major changes list as below:
- Extend the core affinity of each EAL thread to 1:n.
Each lcore stands for a EAL thread rather than a logical core. The change adds new EAL option to allow static lcore to cpusetassginment.
Quoted 1 line
Then a lcore(EAL thread) affinity to a cpuset, original 1:1 mapping is
the special case.
Quoted 2 lines
- Fix the libraries to allow running on any non-EAL thread. It fix the gaps running libraries in non-EAL thread(dynamic created by
user).
Quoted 1 line
Each fix libraries take care the case of
rte_lcore_id()>=
RTE_MAX_LCORE.Sorry if I missed something, but after reading the mailing list threads about this subject, I cannot find an explanation about what problem this series try to solve.
Quoted 6 lines
Can you give some details about which use-case require to have multiple pthreads per cpu? What are the advantage of doing so?
Regards,
Olivier
Quoted 11 lines · Robert Sanford
Sorry if I missed something, but after reading the mailing list threads about this subject, I cannot find an explanation about what problem this series try to solve.
Can you give some details about which use-case require to have multiple pthreads per cpu? What are the advantage of doing so?
Regards,
Olivier
Thanks, indeed I missed it.
v5 cover support multi-pthread per core
In reply to a message not in the archivev5 changes:
reorder some patch and split into addtional two patches rte_thread_get_affinity() return type change to avoid add RTE_RING_PAUSE_REP into config and by default turn off
v4 changes:
new patch fixing strnlen() invalid return in 32bit icc [03/17] update and add more comments on sched_yield() [16/17]
v3 changes:
new patch adding sched_yield() in rte_ring to avoid long spin [16/17]
v2 changes:
add '<number>-<number>' support for EAL option '--lcores' [02/17]
The patch series contain the enhancements of EAL and fixes for libraries
to run multi-pthreads(either EAL or non-EAL thread) per physical core.
Two major changes list as below:
- Extend the core affinity of each EAL thread to 1:n.
Each lcore stands for a EAL thread rather than a logical core.
The change adds new EAL option to allow static lcore to cpuset assginment. Then a lcore(EAL thread) affinity to a cpuset, original 1:1 mapping is the special case.
- Fix the libraries to allow running on any non-EAL thread.
It fix the gaps running libraries in non-EAL thread(dynamic created by user). Each fix libraries take care the case of rte_lcore_id() >= RTE_MAX_LCORE.
Thanks a million for the comments from Konstantin, Bruce, Mirek and Stephen in RFC review.
*** BLURB HERE ***
Cunming Liang (19):
eal: add cpuset into per EAL thread lcore_config
eal: fix PAGE_SIZE redefine complaint on freebsd
eal: new eal option '--lcores' for cpu assignment
eal: fix wrong strnlen() return value in 32bit icc
eal: add support parsing socket_id from cpuset
eal: new TLS definition and API declaration
eal: add eal_common_thread.c for common thread API
eal: standardize init sequence between linux and bsd
eal: add rte_gettid() to acquire unique system tid
eal: apply affinity of EAL thread by assigned cpuset
enic: fix re-define freebsd compile complain
malloc: fix the issue of SOCKET_ID_ANY
log: fix the gap to support non-EAL thread
eal: set _lcore_id and _socket_id to (-1) by default
eal: fix recursive spinlock in non-EAL thraed
mempool: add support to non-EAL thread
ring: add support to non-EAL thread
ring: add sched_yield to avoid spin forever
timer: add support to non-EAL thread
config/common_bsdapp | 1 + config/common_linuxapp | 1 + lib/librte_eal/bsdapp/eal/Makefile | 1 + lib/librte_eal/bsdapp/eal/eal.c | 14 +- lib/librte_eal/bsdapp/eal/eal_lcore.c | 14 + lib/librte_eal/bsdapp/eal/eal_memory.c | 8 +- lib/librte_eal/bsdapp/eal/eal_thread.c | 77 ++---- lib/librte_eal/common/eal_common_log.c | 17 +- lib/librte_eal/common/eal_common_options.c | 308 ++++++++++++++++++++- lib/librte_eal/common/eal_common_thread.c | 150 ++++++++++ lib/librte_eal/common/eal_options.h | 2 + lib/librte_eal/common/eal_thread.h | 47 ++++ .../common/include/generic/rte_spinlock.h | 4 +- lib/librte_eal/common/include/rte_eal.h | 27 ++ lib/librte_eal/common/include/rte_lcore.h | 40 ++- lib/librte_eal/common/include/rte_log.h | 5 + lib/librte_eal/linuxapp/eal/Makefile | 4 + lib/librte_eal/linuxapp/eal/eal.c | 8 +- lib/librte_eal/linuxapp/eal/eal_lcore.c | 15 +- lib/librte_eal/linuxapp/eal/eal_thread.c | 77 ++---- lib/librte_malloc/malloc_heap.h | 7 +- lib/librte_mempool/rte_mempool.h | 18 +- lib/librte_pmd_enic/enic.h | 4 +- lib/librte_pmd_enic/enic_compat.h | 2 +- lib/librte_pmd_enic/vnic/vnic_dev.c | 6 +- lib/librte_ring/rte_ring.h | 41 ++- lib/librte_timer/rte_timer.c | 31 ++- lib/librte_timer/rte_timer.h | 4 +- 28 files changed, 764 insertions(+), 169 deletions(-) create mode 100644 lib/librte_eal/common/eal_common_thread.c
Signature · 1 line
1.8.1.4
A message that is not in the archive (sent off-list or not yet received): 1423728996-3004-1-git-send-email-cunming.liang-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org
PATCH v5 1/19 eal: add cpuset into per EAL thread lcore_config
The patch adds 'cpuset' into per-lcore configure 'lcore_config[]', as the lcore no longer always 1:1 pinning with physical cpu. The lcore now stands for a EAL thread rather than a logical cpu.
It doesn't change the default behavior of 1:1 mapping, but allows to affinity the EAL thread to multiple cpus.
---
v5 changes:
separate eal_memory.c to the new patch
lib/librte_eal/bsdapp/eal/eal_lcore.c | 7 +++++++ lib/librte_eal/common/include/rte_lcore.h | 8 ++++++++ lib/librte_eal/linuxapp/eal/Makefile | 1 + lib/librte_eal/linuxapp/eal/eal_lcore.c | 8 ++++++++ 4 files changed, 24 insertions(+)
lib/librte_eal/bsdapp/eal/eal_lcore.c +7 -0
@@ -76,11 +76,18 @@ rte_eal_cpu_init(void)* ones and enable them by default. */ for (lcore_id =0 ; lcore_id <RTE_MAX_LCORE ; lcore_id++) { +/* init cpuset for per lcore config */ +CPU_ZERO (&lcore_config[lcore_id].cpuset); + lcore_config[lcore_id].detected = (lcore_id < ncpus);if (lcore_config[lcore_id].detected ==0 ) { config->lcore_role[lcore_id] =ROLE_OFF ;continue ; } + +/* By default, lcore 1:1 map to cpu id */ +CPU_SET (lcore_id, &lcore_config[lcore_id].cpuset); +/* By default, each detected core is enabled */ config->lcore_role[lcore_id] =ROLE_RTE ; lcore_config[lcore_id].core_id =cpu_core_id (lcore_id);
lib/librte_eal/common/include/rte_lcore.h +8 -0
@@ -50,6 +50,13 @@ extern "C" {#define LCORE_ID_ANY -1/**< Any lcore. */ +#if defined(__linux__) +typedef cpu_set_t rte_cpuset_t ; +#elif defined(__FreeBSD__) +#include <pthread_np.h> +typedef cpuset_t rte_cpuset_t ; +#endif +/** * Structure storing internal configuration (per-lcore) */
@@ -65,6 +72,7 @@ struct lcore_config {unsigned socket_id;/**< physical socket id for this lcore */ unsigned core_id;/**< core number on socket for this lcore */ int core_index;/**< relative index, starting from 0 */ +rte_cpuset_t cpuset;/**< cpu set which the lcore affinity to */ };/**
lib/librte_eal/linuxapp/eal/Makefile +1 -0
@@ -91,6 +91,7 @@ SRCS-$(CONFIG_RTE_LIBRTE_EAL_LINUXAPP) += eal_common_dev.c SRCS-$(CONFIG_RTE_LIBRTE_EAL_LINUXAPP) += eal_common_options.c CFLAGS_eal.o := -D_GNU_SOURCE +CFLAGS_eal_lcore.o := -D_GNU_SOURCE CFLAGS_eal_thread.o := -D_GNU_SOURCE CFLAGS_eal_log.o := -D_GNU_SOURCE CFLAGS_eal_common_log.o := -D_GNU_SOURCE
lib/librte_eal/linuxapp/eal/eal_lcore.c +8 -0
@@ -158,11 +158,19 @@ rte_eal_cpu_init(void)* ones and enable them by default. */ for (lcore_id =0 ; lcore_id <RTE_MAX_LCORE ; lcore_id++) { +/* init cpuset for per lcore config */ +CPU_ZERO (&lcore_config[lcore_id].cpuset); + +/* in 1:1 mapping, record related cpu detected state */ lcore_config[lcore_id].detected =cpu_detected (lcore_id);if (lcore_config[lcore_id].detected ==0 ) { config->lcore_role[lcore_id] =ROLE_OFF ;continue ; } + +/* By default, lcore 1:1 map to cpu id */ +CPU_SET (lcore_id, &lcore_config[lcore_id].cpuset); +/* By default, each detected core is enabled */ config->lcore_role[lcore_id] =ROLE_RTE ; lcore_config[lcore_id].core_id =cpu_core_id (lcore_id);
Signature · 1 line
1.8.1.4
PATCH v5 2/19 eal: fix PAGE_SIZE redefine complaint on freebsd
In reply to a message not in the archive--- lib/librte_eal/bsdapp/eal/eal_memory.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-)
lib/librte_eal/bsdapp/eal/eal_memory.c +5 -3
@@ -45,7 +45,7 @@#include "eal_internal_cfg.h" #include "eal_filesystem.h" -#define PAGE_SIZE (sysconf(_SC_PAGESIZE)) +#define EAL_PAGE_SIZE (sysconf(_SC_PAGESIZE))/* * Get physical address of any mapped virtual address in the current process.
@@ -93,7 +93,8 @@ rte_eal_contigmem_init(void)char physaddr_str[64 ]; addr =mmap (NULL , hpi->hugepage_sz,PROT_READ |PROT_WRITE , -MAP_SHARED , hpi->lock_descriptor, j *PAGE_SIZE ); +MAP_SHARED , hpi->lock_descriptor, + j *EAL_PAGE_SIZE );if (addr ==MAP_FAILED ) {RTE_LOG (ERR ,EAL ,"Failed to mmap buffer %u from %s\n" , j, hpi->hugedir);
@@ -167,7 +168,8 @@ rte_eal_contigmem_attach(void)struct rte_memseg *seg = &mcfg->memseg[i]; addr =mmap (seg->addr, hpi->hugepage_sz,PROT_READ |PROT_WRITE , -MAP_SHARED |MAP_FIXED , fd_hugepage, i *PAGE_SIZE ); +MAP_SHARED |MAP_FIXED , fd_hugepage, + i *EAL_PAGE_SIZE );if (addr ==MAP_FAILED || addr != seg->addr) {RTE_LOG (ERR ,EAL ,"Failed to mmap buffer %u from %s\n" , i, hpi->hugedir);
Signature · 1 line
1.8.1.4
PATCH v5 3/19 eal: new eal option '--lcores' for cpu assignment
In reply to a message not in the archiveIt supports one new eal long option '--lcores' for EAL thread cpuset assignment.
The format pattern:
--lcores='lcores[@cpus]<,lcores[@cpus]>'
lcores, cpus could be a single digit/range or a group. '(' and ')' are necessary if it's a group.
If not supply '@cpus', the value of cpus uses the same as lcores.
e.g. '1,2@(5-7),(3-5)@(0,2),(0,6),7-8' means starting 9 EAL thread as below
lcore 0 runs on cpuset 0x41 (cpu 0,6)
lcore 1 runs on cpuset 0x2 (cpu 1)
lcore 2 runs on cpuset 0xe0 (cpu 5,6,7)
lcore 3,4,5 runs on cpuset 0x5 (cpu 0,2)
lcore 6 runs on cpuset 0x41 (cpu 0,6)
lcore 7 runs on cpuset 0x80 (cpu 7)
lcore 8 runs on cpuset 0x100 (cpu 8)
---
v5 changes:
add more comments for eal_parse_set
fix some typo
remove inline prefix from convert_to_cpuset() fix a bug introduced on v2 which broke case '(0,6)'
v2 changes:
add '<number>-<number>' support for EAL option '--lcores'
lib/librte_eal/common/eal_common_options.c | 304 ++++++++++++++++++++++++++++- lib/librte_eal/common/eal_options.h | 2 + lib/librte_eal/linuxapp/eal/Makefile | 1 + 3 files changed, 303 insertions(+), 4 deletions(-)
lib/librte_eal/common/eal_common_options.c +300 -4
@@ -45,6 +45,7 @@#include <rte_lcore.h> #include <rte_version.h> #include <rte_devargs.h> +#include <rte_memcpy.h> #include "eal_internal_cfg.h" #include "eal_options.h"
@@ -85,6 +86,7 @@ eal_long_options[] = { {OPT_XEN_DOM0, 0, 0, OPT_XEN_DOM0_NUM}, {OPT_CREATE_UIO_DEV, 1, NULL, OPT_CREATE_UIO_DEV_NUM}, {OPT_VFIO_INTR, 1, NULL, OPT_VFIO_INTR_NUM}, + {OPT_LCORES, 1, 0, OPT_LCORES_NUM}, {0, 0, 0, 0} };
@@ -255,9 +257,11 @@ eal_parse_corelist(const char *corelist)if (min ==RTE_MAX_LCORE ) min = idx;for (idx = min; idx <= max; idx++) { - cfg->lcore_role[idx] =ROLE_RTE ; - lcore_config[idx].core_index = count; - count++; +if (cfg->lcore_role[idx] !=ROLE_RTE ) { + cfg->lcore_role[idx] =ROLE_RTE ; + lcore_config[idx].core_index = count; + count++; + } } min =RTE_MAX_LCORE ; }else
@@ -292,6 +296,283 @@ eal_parse_master_lcore(const char *arg)return 0 ; } +/* +* Parse elem, the elem could be single number/range or '(' ')' group +* 1) A single number elem, it's just a simple digit. e.g. 9 +* 2) A single range elem, two digits with a '-' between. e.g. 2-6 +* 3) A group elem, combines multiple 1) or 2) with '( )'. e.g (0,2-4,6) +* Within group elem, '-' used for a range separator; +* ',' used for a single number. +*/ +static int +eal_parse_set (const char *input,uint16_t set[],unsigned num) +{ +unsigned idx; +const char *str = input; +char *end =NULL ; +unsigned min, max; + +memset (set,0 , num *sizeof (uint16_t )); + +while (isblank (*str)) + str++; + +/* only digit or left bracket is qualify for start point */ +if ((!isdigit (*str) && *str !='(' ) || *str =='\0' ) +return -1 ; + +/* process single number or single range of number */ +if (*str !='(' ) { + errno =0 ; + idx =strtoul (str, &end,10 ); +if (errno || end ==NULL || idx >= num) +return -1 ; +else { +while (isblank (*end)) + end++; + + min = idx; + max = idx; +if (*end =='-' ) { +/* process single <number>-<number> */ + end++; +while (isblank (*end)) + end++; +if (!isdigit (*end)) +return -1 ; + + errno =0 ; + idx =strtoul (end, &end,10 ); +if (errno || end ==NULL || idx >= num) +return -1 ; + max = idx; +while (isblank (*end)) + end++; +if (*end !=',' && *end !='\0' ) +return -1 ; + } + +if (*end !=',' && *end !='\0' && + *end !='@' ) +return -1 ; + +for (idx =RTE_MIN (min, max); + idx <=RTE_MAX (min, max); idx++) + set[idx] =1 ; + +return end - input; + } + } + +/* process set within bracket */ + str++; +while (isblank (*str)) + str++; +if (*str =='\0' ) +return -1 ; + + min =RTE_MAX_LCORE ; +do { + +/* go ahead to the first digit */ +while (isblank (*str)) + str++; +if (!isdigit (*str)) +return -1 ; + +/* get the digit value */ + errno =0 ; + idx =strtoul (str, &end,10 ); +if (errno || end ==NULL || idx >= num) +return -1 ; + +/* go ahead to separator '-',',' and ')' */ +while (isblank (*end)) + end++; +if (*end =='-' ) { +if (min ==RTE_MAX_LCORE ) + min = idx; +else /* avoid continuous '-' */ +return -1 ; + }else if ((*end ==',' ) || (*end ==')' )) { + max = idx; +if (min ==RTE_MAX_LCORE ) + min = idx; +for (idx =RTE_MIN (min, max); + idx <=RTE_MAX (min, max); idx++) + set[idx] =1 ; + + min =RTE_MAX_LCORE ; + }else +return -1 ; + + str = end +1 ; + }while (*end !='\0' && *end !=')' ); + +return str - input; +} + +/* convert from set array to cpuset bitmap */ +static int +convert_to_cpuset (rte_cpuset_t *cpusetp, +uint16_t *set,unsigned num) +{ +unsigned idx; + +CPU_ZERO (cpusetp); + +for (idx =0 ; idx < num; idx++) { +if (!set[idx]) +continue ; + +if (!lcore_config[idx].detected) { +RTE_LOG (ERR ,EAL ,"core %u " +"unavailable\n" , idx); +return -1 ; + } + +CPU_SET (idx, cpusetp); + } + +return 0 ; +} + +/* +* The format pattern: --lcores='lcores[@cpus]<,lcores[@cpus]>' +* lcores, cpus could be a single digit/range or a group. +* '(' and ')' are necessary if it's a group. +* If not supply '@cpus', the value of cpus uses the same as lcores. +* e.g. '1,2@(5-7),(3-5)@(0,2),(0,6),7-8' means start 9 EAL thread as below +* lcore 0 runs on cpuset 0x41 (cpu 0,6) +* lcore 1 runs on cpuset 0x2 (cpu 1) +* lcore 2 runs on cpuset 0xe0 (cpu 5,6,7) +* lcore 3,4,5 runs on cpuset 0x5 (cpu 0,2) +* lcore 6 runs on cpuset 0x41 (cpu 0,6) +* lcore 7 runs on cpuset 0x80 (cpu 7) +* lcore 8 runs on cpuset 0x100 (cpu 8) +*/ +static int +eal_parse_lcores (const char *lcores) +{ +struct rte_config *cfg =rte_eal_get_configuration (); +static uint16_t set[RTE_MAX_LCORE ]; +unsigned idx =0 ; +int i; +unsigned count =0 ; +const char *lcore_start =NULL ; +const char *end =NULL ; +int offset; +rte_cpuset_t cpuset; +int lflags =0 ; +int ret =-1 ; + +if (lcores ==NULL ) +return -1 ; + +/* Remove all blank characters ahead and after */ +while (isblank (*lcores)) + lcores++; + i =strnlen (lcores,sysconf (_SC_ARG_MAX)); +while ((i >0 ) &&isblank (lcores[i -1 ])) + i--; + +CPU_ZERO (&cpuset); + +/* Reset lcore config */ +for (idx =0 ; idx <RTE_MAX_LCORE ; idx++) { + cfg->lcore_role[idx] =ROLE_OFF ; + lcore_config[idx].core_index =-1 ; +CPU_ZERO (&lcore_config[idx].cpuset); + } + +/* Get list of cores */ +do { +while (isblank (*lcores)) + lcores++; +if (*lcores =='\0' ) + goto err; + +/* record lcore_set start point */ + lcore_start = lcores; + +/* go across a complete bracket */ +if (*lcore_start =='(' ) { + lcores +=strcspn (lcores,")" ); +if (*lcores++ =='\0' ) + goto err; + } + +/* scan the separator '@', ','(next) or '\0'(finish) */ + lcores +=strcspn (lcores,"@," ); + +if (*lcores =='@' ) { +/* explict assign cpu_set */ + offset =eal_parse_set (lcores +1 , set,RTE_DIM (set)); +if (offset <0 ) + goto err; + +/* prepare cpu_set and update the end cursor */ +if (0 >convert_to_cpuset (&cpuset, + set,RTE_DIM (set))) + goto err; + end = lcores +1 + offset; + }else {/* ',' or '\0' */ +/* haven't given cpu_set, current loop done */ + end = lcores; + +/* go back to check <number>-<number> */ + offset =strcspn (lcore_start,"(-" ); +if (offset < (end - lcore_start) && + *(lcore_start + offset) !='(' ) + lflags =1 ; + } + +if (*end !=',' && *end !='\0' ) + goto err; + +/* parse lcore_set from start point */ +if (0 >eal_parse_set (lcore_start, set,RTE_DIM (set))) + goto err; + +/* without '@', by default using lcore_set as cpu_set */ +if (*lcores !='@' && +0 >convert_to_cpuset (&cpuset, set,RTE_DIM (set))) + goto err; + +/* start to update lcore_set */ +for (idx =0 ; idx <RTE_MAX_LCORE ; idx++) { +if (!set[idx]) +continue ; + +if (cfg->lcore_role[idx] !=ROLE_RTE ) { + lcore_config[idx].core_index = count; + cfg->lcore_role[idx] =ROLE_RTE ; + count++; + } + +if (lflags) { +CPU_ZERO (&cpuset); +CPU_SET (idx, &cpuset); + } +rte_memcpy (&lcore_config[idx].cpuset, &cpuset, +sizeof (rte_cpuset_t)); + } + + lcores = end +1 ; + }while (*end !='\0' ); + +if (count ==0 ) + goto err; + + cfg->lcore_count = count; + lcores_parsed =1 ; + ret =0 ; + +err: + +return ret; +} +static int eal_parse_syslog (const char *facility,struct internal_config *conf) {
@@ -492,6 +773,13 @@ eal_parse_common_option(int opt, const char *optarg, conf->log_level = log;break ; } +case OPT_LCORES_NUM : +if (eal_parse_lcores (optarg) <0 ) { +RTE_LOG (ERR ,EAL ,"invalid parameter for --" +OPT_LCORES "\n" ); +return -1 ; + } +break ;/* don't know what to do, leave this to caller */ default :
@@ -530,7 +818,7 @@ eal_check_common_options(struct internal_config *internal_cfg)if (!lcores_parsed) {RTE_LOG (ERR ,EAL ,"CPU cores must be enabled with options " -"-c or -l\n" ); +"-c, -l or --lcores\n" );return -1 ; }if (cfg->lcore_role[cfg->master_lcore] !=ROLE_RTE ) {
@@ -586,6 +874,14 @@ eal_common_usage(void)" The argument format is <c1>[-c2][,c3[-c4],...]\n" " where c1, c2, etc are core indexes between 0 and %d\n" " --" OPT_MASTER_LCORE " ID: Core ID that is used as master\n" +" --" OPT_LCORES " MAP: maps between lcore_set to phys_cpu_set\n" +" The argument format is\n" +" 'lcores[@cpus]<,lcores[@cpus],...>'\n" +" lcores and cpus list are grouped by '(' and ')'\n" +" Within the group, '-' is used for range separator,\n" +" ',' is used for single number separator.\n" +" '( )' can be omitted for single element group, '@' \n" +" can be omitted if cpus and lcores has the same value\n" " -n NUM : Number of memory channels\n" " -v : Display version information on startup\n" " -m MB : memory to allocate (see also --" OPT_SOCKET_MEM ")\n"
lib/librte_eal/common/eal_options.h +2 -0
@@ -77,6 +77,8 @@ enum {OPT_CREATE_UIO_DEV_NUM , #define OPT_VFIO_INTR "vfio-intr"OPT_VFIO_INTR_NUM , +#define OPT_LCORES "lcores" +OPT_LCORES_NUM , OPT_LONG_MAX_NUM };
lib/librte_eal/linuxapp/eal/Makefile +1 -0
@@ -99,6 +99,7 @@ CFLAGS_eal_hugepage_info.o := -D_GNU_SOURCE CFLAGS_eal_pci.o := -D_GNU_SOURCE CFLAGS_eal_pci_vfio.o := -D_GNU_SOURCE CFLAGS_eal_common_whitelist.o := -D_GNU_SOURCE +CFLAGS_eal_common_options.o := -D_GNU_SOURCE # workaround for a gcc bug with noreturn attribute # http://gcc.gnu.org/bugzilla/show_bug.cgi?id=12603
Signature · 1 line
1.8.1.4
PATCH v5 4/19 eal: fix wrong strnlen() return value in 32bit icc
In reply to a message not in the archiveThe problem is that strnlen() here may return invalid value with 32bit icc. (actually it returns it’s second parameter,e.g: sysconf(_SC_ARG_MAX)).
It starts to manifest hwen max_len parameter is > 2M and using icc –m32 –O2 (or above).
---
v5 changes:
using strlen instead of strnlen.
lib/librte_eal/common/eal_common_options.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
lib/librte_eal/common/eal_common_options.c +3 -3
@@ -167,7 +167,7 @@ eal_parse_coremask(const char *coremask)if (coremask[0 ] =='0' && ((coremask[1 ] =='x' ) || (coremask[1 ] =='X' ))) coremask +=2 ; - i =strnlen (coremask,PATH_MAX ); + i =strlen (coremask);while ((i >0 ) &&isblank (coremask[i -1 ])) i--;if (i ==0 )
@@ -227,7 +227,7 @@ eal_parse_corelist(const char *corelist)/* Remove all blank characters ahead and after */ while (isblank (*corelist)) corelist++; - i =strnlen (corelist,sysconf (_SC_ARG_MAX)); + i =strlen (corelist);while ((i >0 ) &&isblank (corelist[i -1 ])) i--;
@@ -472,7 +472,7 @@ eal_parse_lcores(const char *lcores)/* Remove all blank characters ahead and after */ while (isblank (*lcores)) lcores++; - i =strnlen (lcores,sysconf (_SC_ARG_MAX)); + i =strlen (lcores);while ((i >0 ) &&isblank (lcores[i -1 ])) i--;
Signature · 1 line
1.8.1.4
PATCH v5 5/19 eal: add support parsing socket_id from cpuset
In reply to a message not in the archiveIt returns the socket_id if all cpus in the cpuset belongs to the same NUMA node, otherwise it will return SOCKET_ID_ANY.
---
v5 changes:
expose cpu_socket_id as eal_cpu_socket_id for linuxapp eal_cpuset_socket_id() remove static inline and move to c file
lib/librte_eal/bsdapp/eal/eal_lcore.c | 7 +++++++ lib/librte_eal/common/eal_thread.h | 11 +++++++++++ lib/librte_eal/linuxapp/eal/eal_lcore.c | 7 ++++--- 3 files changed, 22 insertions(+), 3 deletions(-)
lib/librte_eal/bsdapp/eal/eal_lcore.c +7 -0
@@ -41,6 +41,7 @@#include <rte_debug.h> #include "eal_private.h" +#include "eal_thread.h" /* No topology information available on FreeBSD including NUMA info */ #define cpu_core_id (X ) 0
@@ -112,3 +113,9 @@ rte_eal_cpu_init(void)return 0 ; } + +unsigned +eal_cpu_socket_id (__rte_unused unsigned cpu_id) +{ +return cpu_socket_id (cpu_id); +}
lib/librte_eal/common/eal_thread.h +11 -0
@@ -50,4 +50,15 @@ __attribute__((noreturn)) void *eal_thread_loop(void *arg);*/ void eal_thread_init_master (unsigned lcore_id); +/** +* Get the NUMA socket id from cpu id. +* This function is private to EAL. +* +* @param cpu_id +* The logical process id. +* @return +* socket_id or SOCKET_ID_ANY +*/ +unsigned eal_cpu_socket_id (unsigned cpu_id); +#endif /* EAL_THREAD_H */
lib/librte_eal/linuxapp/eal/eal_lcore.c +4 -3
@@ -45,6 +45,7 @@#include "eal_private.h" #include "eal_filesystem.h" +#include "eal_thread.h" #define SYS_CPU_DIR "/sys/devices/system/cpu/cpu%u"#define CORE_ID_FILE "topology/core_id"
@@ -71,8 +72,8 @@ cpu_detected(unsigned lcore_id)* Note: physical package id != NUMA node, but we use it as a * fallback for kernels which don't create a nodeY link */ -static unsigned -cpu_socket_id (unsigned lcore_id) +unsigned +eal_cpu_socket_id (unsigned lcore_id) {const char node_prefix[] ="node" ;const size_t prefix_len =sizeof (node_prefix) -1 ;
@@ -174,7 +175,7 @@ rte_eal_cpu_init(void)/* By default, each detected core is enabled */ config->lcore_role[lcore_id] =ROLE_RTE ; lcore_config[lcore_id].core_id =cpu_core_id (lcore_id); - lcore_config[lcore_id].socket_id =cpu_socket_id (lcore_id); + lcore_config[lcore_id].socket_id =eal_cpu_socket_id (lcore_id); if (lcore_config[lcore_id].socket_id >= RTE_MAX_NUMA_NODES)#ifdef RTE_EAL_ALLOW_INV_SOCKET_ID lcore_config[lcore_id].socket_id =0 ;
Signature · 1 line
1.8.1.4
PATCH v5 6/19 eal: new TLS definition and API declaration
In reply to a message not in the archive1. add two TLS *_socket_id* and *_cpuset*
2. add two external API rte_thread_set/get_affinity
3. add one internal API eal_thread_dump_affinity
---
v5 changes:
add comments for RTE_CPU_AFFINITY_STR_LEN
update comments for eal_thread_dump_affinity()
return void for rte_thread_get_affinity()
move rte_socket_id() change to another patch
lib/librte_eal/bsdapp/eal/eal_thread.c | 2 ++ lib/librte_eal/common/eal_thread.h | 36 +++++++++++++++++++++++++++++++ lib/librte_eal/common/include/rte_lcore.h | 26 +++++++++++++++++++++- lib/librte_eal/linuxapp/eal/eal_thread.c | 2 ++ 4 files changed, 65 insertions(+), 1 deletion(-)
lib/librte_eal/bsdapp/eal/eal_thread.c +2 -0
@@ -56,6 +56,8 @@#include "eal_thread.h" RTE_DEFINE_PER_LCORE (unsigned, _lcore_id); +RTE_DEFINE_PER_LCORE (unsigned, _socket_id); +RTE_DEFINE_PER_LCORE (rte_cpuset_t, _cpuset);/* * Send a message to a slave lcore identified by slave_id to call a
lib/librte_eal/common/eal_thread.h +36 -0
@@ -34,6 +34,8 @@#ifndef EAL_THREAD_H #define EAL_THREAD_H +#include <rte_lcore.h> +/** * basic loop of thread, called for each thread by eal_init(). *
@@ -61,4 +63,38 @@ void eal_thread_init_master(unsigned lcore_id);*/ unsigned eal_cpu_socket_id (unsigned cpu_id); +/** +* Get the NUMA socket id from cpuset. +* This function is private to EAL. +* +* @param cpusetp +* The point to a valid cpu set. +* @return +* socket_id or SOCKET_ID_ANY +*/ +int eal_cpuset_socket_id (rte_cpuset_t *cpusetp); + +/** +* Default buffer size to use with eal_thread_dump_affinity() +*/ +#define RTE_CPU_AFFINITY_STR_LEN 256 + +/** +* Dump the current pthread cpuset. +* This function is private to EAL. +* +* Note: +* If the dump size is greater than the size of given buffer, +* the string will be truncated and with '\0' at the end. +* +* @param str +* The string buffer the cpuset will dump to. +* @param size +* The string buffer size. +* @return +* 0 for success, -1 if truncation happens. +*/ +int +eal_thread_dump_affinity (char *str,unsigned size); +#endif /* EAL_THREAD_H */
lib/librte_eal/common/include/rte_lcore.h +25 -1
@@ -80,7 +80,9 @@ struct lcore_config {*/ extern struct lcore_config lcore_config[RTE_MAX_LCORE ]; -RTE_DECLARE_PER_LCORE (unsigned, _lcore_id);/**< Per core "core id". */ +RTE_DECLARE_PER_LCORE (unsigned, _lcore_id);/**< Per thread "lcore id". */ +RTE_DECLARE_PER_LCORE (unsigned, _socket_id);/**< Per thread "socket id". */ +RTE_DECLARE_PER_LCORE (rte_cpuset_t, _cpuset);/**< Per thread "cpuset". */ /** * Return the ID of the execution unit we are running on.
@@ -229,6 +231,28 @@ rte_get_next_lcore(unsigned i, int skip_master, int wrap) i<RTE_MAX_LCORE ; \ i = rte_get_next_lcore(i, 1, 0)) +/** +* Set core affinity of the current thread. +* Support both EAL and none-EAL thread and update TLS. +* +* @param cpusetp +* Point to cpu_set_t for setting current thread affinity. +* @return +* On success, return 0; otherwise return -1; +*/ +int rte_thread_set_affinity (rte_cpuset_t *cpusetp); + +/** +* Get core affinity of the current thread. +* +* @param cpusetp +* Point to cpu_set_t for getting current thread cpu affinity. +* It presumes input is not NULL, otherwise it causes panic. +* +*/ +void rte_thread_get_affinity (rte_cpuset_t *cpusetp); + + #ifdef __cplusplus }#endif
lib/librte_eal/linuxapp/eal/eal_thread.c +2 -0
@@ -56,6 +56,8 @@#include "eal_thread.h" RTE_DEFINE_PER_LCORE (unsigned, _lcore_id); +RTE_DEFINE_PER_LCORE (unsigned, _socket_id); +RTE_DEFINE_PER_LCORE (rte_cpuset_t, _cpuset);/* * Send a message to a slave lcore identified by slave_id to call a
Signature · 1 line
1.8.1.4
PATCH v5 7/19 eal: add eal_common_thread.c for common thread API
In reply to a message not in the archiveThe API works for both EAL thread and none EAL thread. When calling rte_thread_set_affinity, the *_socket_id* and *_cpuset* of calling thread will be updated if the thread successful set the cpu affinity.
---
v5 changes:
refine code of rte_thread_set_affinity() change rte_thread_get_affinity() return to void
lib/librte_eal/bsdapp/eal/Makefile | 1 + lib/librte_eal/common/eal_common_thread.c | 150 ++++++++++++++++++++++++++++++ lib/librte_eal/linuxapp/eal/Makefile | 2 + 3 files changed, 153 insertions(+) create mode 100644 lib/librte_eal/common/eal_common_thread.c
lib/librte_eal/bsdapp/eal/Makefile +1 -0
@@ -77,6 +77,7 @@ SRCS-$(CONFIG_RTE_LIBRTE_EAL_BSDAPP) += eal_common_hexdump.c SRCS-$(CONFIG_RTE_LIBRTE_EAL_BSDAPP) += eal_common_devargs.c SRCS-$(CONFIG_RTE_LIBRTE_EAL_BSDAPP) += eal_common_dev.c SRCS-$(CONFIG_RTE_LIBRTE_EAL_BSDAPP) += eal_common_options.c +SRCS-$(CONFIG_RTE_LIBRTE_EAL_BSDAPP) += eal_common_thread.c CFLAGS_eal.o := -D_GNU_SOURCE #CFLAGS_eal_thread.o := -D_GNU_SOURCE
lib/librte_eal/common/eal_common_thread.c new file +150 -0
150 lines not on this page · raw message
lib/librte_eal/linuxapp/eal/Makefile +2 -0
@@ -89,6 +89,7 @@ SRCS-$(CONFIG_RTE_LIBRTE_EAL_LINUXAPP) += eal_common_hexdump.c SRCS-$(CONFIG_RTE_LIBRTE_EAL_LINUXAPP) += eal_common_devargs.c SRCS-$(CONFIG_RTE_LIBRTE_EAL_LINUXAPP) += eal_common_dev.c SRCS-$(CONFIG_RTE_LIBRTE_EAL_LINUXAPP) += eal_common_options.c +SRCS-$(CONFIG_RTE_LIBRTE_EAL_LINUXAPP) += eal_common_thread.c CFLAGS_eal.o := -D_GNU_SOURCE CFLAGS_eal_lcore.o := -D_GNU_SOURCE
@@ -100,6 +101,7 @@ CFLAGS_eal_pci.o := -D_GNU_SOURCE CFLAGS_eal_pci_vfio.o := -D_GNU_SOURCE CFLAGS_eal_common_whitelist.o := -D_GNU_SOURCE CFLAGS_eal_common_options.o := -D_GNU_SOURCE +CFLAGS_eal_common_thread.o := -D_GNU_SOURCE # workaround for a gcc bug with noreturn attribute # http://gcc.gnu.org/bugzilla/show_bug.cgi?id=12603
Signature · 1 line
1.8.1.4
PATCH v5 8/19 eal: standardize init sequence between linux and bsd
In reply to a message not in the archive--- lib/librte_eal/bsdapp/eal/eal.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
lib/librte_eal/bsdapp/eal/eal.c +2 -2
@@ -509,6 +509,8 @@ rte_eal_init(int argc, char **argv)rte_eal_mcfg_complete (); +eal_thread_init_master (rte_config.master_lcore); +if (rte_eal_dev_init () <0 )rte_panic ("Cannot init pmd devices\n" );
@@ -532,8 +534,6 @@ rte_eal_init(int argc, char **argv)rte_panic ("Cannot create thread\n" ); } -eal_thread_init_master (rte_config.master_lcore); -/* * Launch a dummy function on all slave lcores, so that master lcore * knows they are all ready when this function returns.
Signature · 1 line
1.8.1.4
PATCH v5 9/19 eal: add rte_gettid() to acquire unique system tid
In reply to a message not in the archiveThe rte_gettid() wraps the linux and freebsd syscall gettid(). It provides a persistent unique thread id for the calling thread. It will save the unique id in TLS on the first time.
--- lib/librte_eal/bsdapp/eal/eal_thread.c | 9 +++++++++ lib/librte_eal/common/include/rte_eal.h | 27 +++++++++++++++++++++++++++ lib/librte_eal/linuxapp/eal/eal_thread.c | 7 +++++++ 3 files changed, 43 insertions(+)
lib/librte_eal/bsdapp/eal/eal_thread.c +9 -0
@@ -39,6 +39,7 @@#include <sched.h> #include <pthread_np.h> #include <sys/queue.h> +#include <sys/thr.h> #include <rte_debug.h> #include <rte_atomic.h>
@@ -233,3 +234,11 @@ eal_thread_loop(__attribute__((unused)) void *arg)/* pthread_exit(NULL); */ /* return NULL; */ } + +/* require calling thread tid by gettid() */ +int rte_sys_gettid (void ) +{ +long lwpid; +thr_self (&lwpid); +return (int )lwpid; +}
lib/librte_eal/common/include/rte_eal.h +27 -0
@@ -41,6 +41,9 @@*/ #include <stdint.h> +#include <sched.h> + +#include <rte_per_lcore.h> #ifdef __cplusplusextern "C" {
@@ -262,6 +265,30 @@ rte_set_application_usage_hook( rte_usage_hook_t usage_func );*/ int rte_eal_has_hugepages (void ); +/** +* A wrap API for syscall gettid. +* +* @return +* On success, returns the thread ID of calling process. +* It always successful. +*/ +int rte_sys_gettid (void ); + +/** +* Get system unique thread id. +* +* @return +* On success, returns the thread ID of calling process. +* It always successful. +*/ +static inline int rte_gettid (void ) +{ + static RTE_DEFINE_PER_LCORE(int, _thread_id) = -1; +if (RTE_PER_LCORE (_thread_id) ==-1 ) +RTE_PER_LCORE (_thread_id) =rte_sys_gettid (); +return RTE_PER_LCORE (_thread_id); +} + #ifdef __cplusplus }#endif
lib/librte_eal/linuxapp/eal/eal_thread.c +7 -0
@@ -39,6 +39,7 @@#include <pthread.h> #include <sched.h> #include <sys/queue.h> +#include <sys/syscall.h> #include <rte_debug.h> #include <rte_atomic.h>
@@ -233,3 +234,9 @@ eal_thread_loop(__attribute__((unused)) void *arg)/* pthread_exit(NULL); */ /* return NULL; */ } + +/* require calling thread tid by gettid() */ +int rte_sys_gettid (void ) +{ +return (int )syscall (SYS_gettid); +}
Signature · 1 line
1.8.1.4
PATCH v5 10/19 eal: apply affinity of EAL thread by assigned cpuset
In reply to a message not in the archiveEAL threads use assigned cpuset to set core affinity during startup. It keeps 1:1 mapping, if no '--lcores' option is used.
---
v5 changes:
add return check for dump_affinity
call rte_thread_set_affinity() directly during EAL thread set
lib/librte_eal/bsdapp/eal/eal.c | 10 +++-- lib/librte_eal/bsdapp/eal/eal_thread.c | 64 ++++++------------------------ lib/librte_eal/common/include/rte_lcore.h | 2 +- lib/librte_eal/linuxapp/eal/eal.c | 8 +++- lib/librte_eal/linuxapp/eal/eal_thread.c | 66 ++++++------------------------- 5 files changed, 37 insertions(+), 113 deletions(-)
lib/librte_eal/bsdapp/eal/eal.c +7 -3
@@ -432,6 +432,7 @@ rte_eal_init(int argc, char **argv)int i, fctret, ret;pthread_t thread_id;static rte_atomic32_t run_once =RTE_ATOMIC32_INIT (0 ); +char cpuset[RTE_CPU_AFFINITY_STR_LEN ];if (!rte_atomic32_test_and_set (&run_once))return -1 ;
@@ -502,15 +503,18 @@ rte_eal_init(int argc, char **argv)if (rte_eal_pci_init () <0 )rte_panic ("Cannot init PCI\n" ); -RTE_LOG (DEBUG ,EAL ,"Master core %u is ready (tid=%p)\n" , - rte_config.master_lcore, thread_id); -eal_check_mem_on_local_socket ();rte_eal_mcfg_complete ();eal_thread_init_master (rte_config.master_lcore); + ret =eal_thread_dump_affinity (cpuset,RTE_CPU_AFFINITY_STR_LEN ); + +RTE_LOG (DEBUG ,EAL ,"Master lcore %u is ready (tid=%p;cpuset=[%s%s])\n" , + rte_config.master_lcore, thread_id, cpuset, + ret ==0 ?"" :"..." ); +if (rte_eal_dev_init () <0 )rte_panic ("Cannot init pmd devices\n" );
lib/librte_eal/bsdapp/eal/eal_thread.c +11 -53
90 lines not on this page · raw message
lib/librte_eal/common/include/rte_lcore.h +1 -1
@@ -148,7 +148,7 @@ rte_lcore_index(int lcore_id)static inline unsigned rte_socket_id (void ) { -return lcore_config[rte_lcore_id ()].socket_id; +return RTE_PER_LCORE (_socket_id); }/**
lib/librte_eal/linuxapp/eal/eal.c +6 -2
@@ -702,6 +702,7 @@ rte_eal_init(int argc, char **argv)static rte_atomic32_t run_once =RTE_ATOMIC32_INIT (0 );struct shared_driver *solib =NULL ;const char *logid; +char cpuset[RTE_CPU_AFFINITY_STR_LEN ];if (!rte_atomic32_test_and_set (&run_once))return -1 ;
@@ -802,8 +803,11 @@ rte_eal_init(int argc, char **argv)eal_thread_init_master (rte_config.master_lcore); -RTE_LOG (DEBUG ,EAL ,"Master core %u is ready (tid=%x)\n" , - rte_config.master_lcore, (int )thread_id); + ret =eal_thread_dump_affinity (cpuset,RTE_CPU_AFFINITY_STR_LEN ); + +RTE_LOG (DEBUG ,EAL ,"Master lcore %u is ready (tid=%x;cpuset=[%s%s])\n" , + rte_config.master_lcore, (int )thread_id, cpuset, + ret ==0 ?"" :"..." );if (rte_eal_dev_init () <0 )rte_panic ("Cannot init pmd devices\n" );
lib/librte_eal/linuxapp/eal/eal_thread.c +12 -54
95 lines not on this page · raw message
Signature · 1 line
1.8.1.4
PATCH v5 11/19 enic: fix re-define freebsd compile complain
In reply to a message not in the archiveSome macro already been defined by freebsd 'sys/param.h'.
---
v5 changes:
rename the redefined MACRO instead of undefine them
lib/librte_pmd_enic/enic.h | 4 ++-- lib/librte_pmd_enic/enic_compat.h | 2 +- lib/librte_pmd_enic/vnic/vnic_dev.c | 6 +++--- 3 files changed, 6 insertions(+), 6 deletions(-)
lib/librte_pmd_enic/enic.h +2 -2
@@ -66,9 +66,9 @@#define ENIC_CALC_IP_CKSUM 1#define ENIC_CALC_TCP_UDP_CKSUM 2#define ENIC_MAX_MTU 9000 -#define PAGE_SIZE 4096 +#define ENIC_PAGE_SIZE 4096#define PAGE_ROUND_UP (x) \ - ((((unsigned long)(x)) + PAGE_SIZE-1) & (~(PAGE_SIZE-1))) + ((((unsigned long)(x)) + ENIC_PAGE_SIZE-1) & (~(ENIC_PAGE_SIZE-1)))#define ENICPMD_VFIO_PATH "/dev/vfio/vfio"/*#define ENIC_DESC_COUNT_MAKE_ODD (x) do{if ((~(x)) & 1) { (x)--; } }while(0)*/
lib/librte_pmd_enic/enic_compat.h +1 -1
@@ -67,7 +67,7 @@ #define pr_warn(y, args...) dev_warning(0, y, ##args)#define BUG () pr_err("BUG at %s:%d", __func__, __LINE__) -#define ALIGN (x, a) __ALIGN_MASK(x, (typeof(x))(a)-1) +#define VNIC_ALIGN (x, a) __ALIGN_MASK(x, (typeof(x))(a)-1)#define __ALIGN_MASK (x, mask) (((x)+(mask))&~(mask))#define udelay usleep#define DIV_ROUND_UP (n, d) (((n) + (d) - 1) / (d))
lib/librte_pmd_enic/vnic/vnic_dev.c +3 -3
@@ -242,9 +242,9 @@ unsigned int vnic_dev_desc_ring_size(struct vnic_dev_ring *ring,if (desc_count ==0 ) desc_count =4096 ; - ring->desc_count =ALIGN (desc_count, count_align); + ring->desc_count =VNIC_ALIGN (desc_count, count_align); - ring->desc_size =ALIGN (desc_size, desc_align); + ring->desc_size =VNIC_ALIGN (desc_size, desc_align); ring->size = ring->desc_count * ring->desc_size; ring->size_unaligned = ring->size + ring->base_align;
@@ -294,7 +294,7 @@ int vnic_dev_alloc_desc_ring(__attribute__((unused)) struct vnic_dev *vdev, ring->base_addr_unaligned = (dma_addr_t )rz->phys_addr; - ring->base_addr =ALIGN (ring->base_addr_unaligned, + ring->base_addr =VNIC_ALIGN (ring->base_addr_unaligned, ring->base_align); ring->descs = (u8 *)ring->descs_unaligned + (ring->base_addr - ring->base_addr_unaligned);
Signature · 1 line
1.8.1.4
PATCH v5 12/19 malloc: fix the issue of SOCKET_ID_ANY
In reply to a message not in the archiveAdd check for rte_socket_id(), avoid get unexpected return like (-1).
--- lib/librte_malloc/malloc_heap.h | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)
lib/librte_malloc/malloc_heap.h +6 -1
@@ -44,7 +44,12 @@ extern "C" {static inline unsigned malloc_get_numa_socket (void ) { -return rte_socket_id (); +unsigned socket_id =rte_socket_id (); + +if (socket_id == (unsigned )SOCKET_ID_ANY ) +return 0 ; + +return socket_id; } void *
Signature · 1 line
1.8.1.4
PATCH v5 13/19 log: fix the gap to support non-EAL thread
In reply to a message not in the archiveFor those non-EAL thread, *_lcore_id* is invalid and probably larger than RTE_MAX_LCORE. The patch adds the check and allows only EAL thread using EAL per thread log level and log type. Others shares the global log level.
--- lib/librte_eal/common/eal_common_log.c | 17 +++++++++++++++-- lib/librte_eal/common/include/rte_log.h | 5 +++++ 2 files changed, 20 insertions(+), 2 deletions(-)
lib/librte_eal/common/eal_common_log.c +15 -2
@@ -193,11 +193,20 @@ rte_set_log_type(uint32_t type, int enable) rte_logs.type &= (~type); } +/* Get global log type */ +uint32_t +rte_get_log_type (void ) +{ +return rte_logs.type; +} +/* get the current loglevel for the message beeing processed */ int rte_log_cur_msg_loglevel (void ) {unsigned lcore_id; lcore_id =rte_lcore_id (); +if (lcore_id >=RTE_MAX_LCORE ) +return rte_get_log_level ();return log_cur_msg[lcore_id].loglevel; }
@@ -206,6 +215,8 @@ int rte_log_cur_msg_logtype(void) {unsigned lcore_id; lcore_id =rte_lcore_id (); +if (lcore_id >=RTE_MAX_LCORE ) +return rte_get_log_type ();return log_cur_msg[lcore_id].logtype; }
@@ -265,8 +276,10 @@ rte_vlog(__attribute__((unused)) uint32_t level,/* save loglevel and logtype in a global per-lcore variable */ lcore_id =rte_lcore_id (); - log_cur_msg[lcore_id].loglevel = level; - log_cur_msg[lcore_id].logtype = logtype; +if (lcore_id <RTE_MAX_LCORE ) { + log_cur_msg[lcore_id].loglevel = level; + log_cur_msg[lcore_id].logtype = logtype; + } ret =vfprintf (f, format, ap);fflush (f);
lib/librte_eal/common/include/rte_log.h +5 -0
@@ -144,6 +144,11 @@ uint32_t rte_get_log_level(void);void rte_set_log_type (uint32_t type,int enable);/** +* Get the global log type. +*/ +uint32_t rte_get_log_type (void ); + +/** * Get the current loglevel for the message being processed. * * Before calling the user-defined stream for logging, the log
Signature · 1 line
1.8.1.4
PATCH v5 14/19 eal: set _lcore_id and _socket_id to (-1) by default
In reply to a message not in the archiveFor those none EAL thread, *_lcore_id* shall always be LCORE_ID_ANY. The libraries using *_lcore_id* as index need to take care. *_socket_id* always be SOCKET_ID_ANY unitl the thread changes the affinity by rte_thread_set_affinity()
---
v5 changes:
define LCORE_ID_ANY as UINT32_MAX
lib/librte_eal/bsdapp/eal/eal_thread.c | 4 ++-- lib/librte_eal/common/include/rte_lcore.h | 4 ++-- lib/librte_eal/linuxapp/eal/eal_thread.c | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-)
lib/librte_eal/bsdapp/eal/eal_thread.c +2 -2
@@ -56,8 +56,8 @@#include "eal_private.h" #include "eal_thread.h" -RTE_DEFINE_PER_LCORE (unsigned, _lcore_id); -RTE_DEFINE_PER_LCORE (unsigned, _socket_id); +RTE_DEFINE_PER_LCORE (unsigned, _lcore_id) =LCORE_ID_ANY ; +RTE_DEFINE_PER_LCORE (unsigned, _socket_id) = (unsigned )SOCKET_ID_ANY ;RTE_DEFINE_PER_LCORE (rte_cpuset_t, _cpuset);/*
lib/librte_eal/common/include/rte_lcore.h +2 -2
@@ -48,7 +48,7 @@extern "C" {#endif -#define LCORE_ID_ANY -1/**< Any lcore. */ +#define LCORE_ID_ANY UINT32_MAX/**< Any lcore. */ #if defined(__linux__)typedef cpu_set_t rte_cpuset_t ;
@@ -87,7 +87,7 @@ RTE_DECLARE_PER_LCORE(rte_cpuset_t, _cpuset); /**< Per thread "cpuset". *//** * Return the ID of the execution unit we are running on. * @return -* Logical core ID +* Logical core ID(in EAL thread) or LCORE_ID_ANY(in non-EAL thread) */ static inline unsigned rte_lcore_id (void )
lib/librte_eal/linuxapp/eal/eal_thread.c +2 -2
@@ -56,8 +56,8 @@#include "eal_private.h" #include "eal_thread.h" -RTE_DEFINE_PER_LCORE (unsigned, _lcore_id); -RTE_DEFINE_PER_LCORE (unsigned, _socket_id); +RTE_DEFINE_PER_LCORE (unsigned, _lcore_id) =LCORE_ID_ANY ; +RTE_DEFINE_PER_LCORE (unsigned, _socket_id) = (unsigned )SOCKET_ID_ANY ;RTE_DEFINE_PER_LCORE (rte_cpuset_t, _cpuset);/*
Signature · 1 line
1.8.1.4
PATCH v5 15/19 eal: fix recursive spinlock in non-EAL thraed
In reply to a message not in the archiveIn non-EAL thread, lcore_id alrways be LCORE_ID_ANY. It cann't be used as unique id for recursive spinlock. Then use rte_gettid() to replace it.
--- lib/librte_eal/common/include/generic/rte_spinlock.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
lib/librte_eal/common/include/generic/rte_spinlock.h +2 -2
@@ -179,7 +179,7 @@ static inline void rte_spinlock_recursive_init(rte_spinlock_recursive_t *slr)*/ static inline void rte_spinlock_recursive_lock (rte_spinlock_recursive_t *slr) { -int id =rte_lcore_id (); +int id =rte_gettid ();if (slr->user != id) {rte_spinlock_lock (&slr->sl);
@@ -212,7 +212,7 @@ static inline void rte_spinlock_recursive_unlock(rte_spinlock_recursive_t *slr)*/ static inline int rte_spinlock_recursive_trylock (rte_spinlock_recursive_t *slr) { -int id =rte_lcore_id (); +int id =rte_gettid ();if (slr->user != id) {if (rte_spinlock_trylock (&slr->sl) ==0 )
Signature · 1 line
1.8.1.4
PATCH v5 16/19 mempool: add support to non-EAL thread
In reply to a message not in the archiveFor non-EAL thread, bypass per lcore cache, directly use ring pool. It allows using rte_mempool in either EAL thread or any user pthread. As in non-EAL thread, it directly rely on rte_ring and it's none preemptive. It doesn't suggest to run multi-pthread/cpu which compete the rte_mempool. It will get bad performance and has critical risk if scheduling policy is RT. Haven't found significant performance decrease by mempool_perf_test.
---
v5 changes:
check __lcore_id with LCORE_ID_ANY instead of RTE_MAX_LCORE
lib/librte_mempool/rte_mempool.h | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-)
lib/librte_mempool/rte_mempool.h +11 -7
@@ -198,10 +198,12 @@ struct rte_mempool {* Number to add to the object-oriented statistics. */ #ifdef RTE_LIBRTE_MEMPOOL_DEBUG -#define __MEMPOOL_STAT_ADD (mp, name, n) do { \ - unsigned __lcore_id = rte_lcore_id(); \ - mp->stats[__lcore_id].name##_objs += n; \ - mp->stats[__lcore_id].name##_bulk += 1; \ +#define __MEMPOOL_STAT_ADD (mp, name, n) do { \ + unsigned __lcore_id = rte_lcore_id(); \ + if (__lcore_id != LCORE_ID_ANY) { \ + mp->stats[__lcore_id].name##_objs += n; \ + mp->stats[__lcore_id].name##_bulk += 1; \ + } \ } while(0)#else #define __MEMPOOL_STAT_ADD (mp, name, n) do {} while(0)
@@ -767,8 +769,9 @@ __mempool_put_bulk(struct rte_mempool *mp, void * const *obj_table,__MEMPOOL_STAT_ADD (mp, put, n);#if RTE_MEMPOOL_CACHE_MAX_SIZE >0 -/* cache is not enabled or single producer */ -if (unlikely (cache_size ==0 || is_mp ==0 )) +/* cache is not enabled or single producer or none EAL thread */ +if (unlikely (cache_size ==0 || is_mp ==0 || + lcore_id ==LCORE_ID_ANY )) goto ring_enqueue;/* Go straight to ring if put would overflow mem allocated for cache */
@@ -952,7 +955,8 @@ __mempool_get_bulk(struct rte_mempool *mp, void **obj_table,uint32_t cache_size = mp->cache_size;/* cache is not enabled or single consumer */ -if (unlikely (cache_size ==0 || is_mc ==0 || n >= cache_size)) +if (unlikely (cache_size ==0 || is_mc ==0 || + n >= cache_size || lcore_id ==LCORE_ID_ANY )) goto ring_dequeue; cache = &mp->local_cache[lcore_id];
Signature · 1 line
1.8.1.4
PATCH v5 17/19 ring: add support to non-EAL thread
In reply to a message not in the archivering debug stat won't take care non-EAL thread.
---
v5 changes:
check __lcore_id with LCORE_ID_ANY instead of RTE_MAX_LCORE
lib/librte_ring/rte_ring.h | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-)
lib/librte_ring/rte_ring.h +6 -4
@@ -188,10 +188,12 @@ struct rte_ring {* The number to add to the object-oriented statistics. */ #ifdef RTE_LIBRTE_RING_DEBUG -#define __RING_STAT_ADD (r, name, n) do { \ - unsigned __lcore_id = rte_lcore_id(); \ - r->stats[__lcore_id].name##_objs += n; \ - r->stats[__lcore_id].name##_bulk += 1; \ +#define __RING_STAT_ADD (r, name, n) do { \ + unsigned __lcore_id = rte_lcore_id(); \ + if (__lcore_id != LCORE_ID_ANY) { \ + r->stats[__lcore_id].name##_objs += n; \ + r->stats[__lcore_id].name##_bulk += 1; \ + } \ } while(0)#else #define __RING_STAT_ADD (r, name, n) do {} while(0)
Signature · 1 line
1.8.1.4
PATCH v5 18/19 ring: add sched_yield to avoid spin forever
In reply to a message not in the archiveAdd a sched_yield() syscall if the thread spins for too long, waiting other thread to finish its operations on the ring. That gives pre-empted thread a chance to proceed and finish with ring enqnue/dequeue operation.
The purpose is to reduce contention on the ring. By ring_perf_test, it doesn't shows additional perf penalty.
---
v5 changes:
add RTE_RING_PAUSE_REP to config file
v4 changes:
update and add more comments on sched_yield()
v3 changes:
new patch adding sched_yield() in rte_ring to avoid long spin
config/common_bsdapp | 1 + config/common_linuxapp | 1 + lib/librte_ring/rte_ring.h | 31 +++++++++++++++++++++++++++---- 3 files changed, 29 insertions(+), 4 deletions(-)
config/common_bsdapp +1 -0
@@ -234,6 +234,7 @@ CONFIG_RTE_PMD_PACKET_PREFETCH=y CONFIG_RTE_LIBRTE_RING=y CONFIG_RTE_LIBRTE_RING_DEBUG=n CONFIG_RTE_RING_SPLIT_PROD_CONS=n +CONFIG_RTE_RING_PAUSE_REP=n # # Compile librte_mempool
config/common_linuxapp +1 -0
@@ -242,6 +242,7 @@ CONFIG_RTE_PMD_PACKET_PREFETCH=y CONFIG_RTE_LIBRTE_RING=y CONFIG_RTE_LIBRTE_RING_DEBUG=n CONFIG_RTE_RING_SPLIT_PROD_CONS=n +CONFIG_RTE_RING_PAUSE_REP=n # # Compile librte_mempool
lib/librte_ring/rte_ring.h +27 -4
@@ -127,6 +127,11 @@ struct rte_ring_debug_stats {#define RTE_RING_NAMESIZE 32/**< The maximum length of a ring name. */ #define RTE_RING_MZ_PREFIX "RG_" +#ifndef RTE_RING_PAUSE_REP +#define RTE_RING_PAUSE_REP 0/**< yield after pause num of times, +* no yield if RTE_RING_PAUSE_REP not defined. */ +#endif +/** * An RTE ring structure. *
@@ -410,7 +415,7 @@ __rte_ring_mp_do_enqueue(struct rte_ring *r, void * const *obj_table,uint32_t cons_tail, free_entries;const unsigned max = n;int success; -unsigned i; +unsigned i, rep =0 ;uint32_t mask = r->prod.mask;int ret;
@@ -468,9 +473,18 @@ __rte_ring_mp_do_enqueue(struct rte_ring *r, void * const *obj_table,* If there are other enqueues in progress that preceded us, * we need to wait for them to complete */ -while (unlikely (r->prod.tail != prod_head)) +while (unlikely (r->prod.tail != prod_head)) {rte_pause (); +/* Set RTE_RING_PAUSE_REP to avoid spin too long waiting for +* other thread finish. It gives pre-empted thread a chance +* to proceed and finish with ring denqnue operation. */ +if (RTE_RING_PAUSE_REP && + ++rep ==RTE_RING_PAUSE_REP ) { + rep =0 ; +sched_yield (); + } + } r->prod.tail = prod_next;return ret; }
@@ -589,7 +603,7 @@ __rte_ring_mc_do_dequeue(struct rte_ring *r, void **obj_table,uint32_t cons_next, entries;const unsigned max = n;int success; -unsigned i; +unsigned i, rep =0 ;uint32_t mask = r->prod.mask;/* move cons.head atomically */
@@ -634,9 +648,18 @@ __rte_ring_mc_do_dequeue(struct rte_ring *r, void **obj_table,* If there are other dequeues in progress that preceded us, * we need to wait for them to complete */ -while (unlikely (r->cons.tail != cons_head)) +while (unlikely (r->cons.tail != cons_head)) {rte_pause (); +/* Set RTE_RING_PAUSE_REP to avoid spin too long waiting for +* other thread finish. It gives pre-empted thread a chance +* to proceed and finish with ring denqnue operation. */ +if (RTE_RING_PAUSE_REP && + ++rep ==RTE_RING_PAUSE_REP ) { + rep =0 ; +sched_yield (); + } + }__RING_STAT_ADD (r, deq_success, n); r->cons.tail = cons_next;
Signature · 1 line
1.8.1.4
A message that is not in the archive (sent off-list or not yet received): 1423728996-3004-19-git-send-email-cunming.liang-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org
Re: [PATCH v5 18/19] ring: add sched_yield to avoid spin forever
Hi,
Quoted 25 lines · Cunming Liang
Add a
sched_yield()syscall if the thread spins for too long, waiting other thread to finish its operations on the ring. That gives pre-empted thread a chance to proceed and finish with ring enqnue/dequeue operation.
The purpose is to reduce contention on the ring. Byring_perf_test, it doesn't shows additional perf penalty.Signed-off-by Cunming Liang <[email protected]>---
v5 changes:
addRTE_RING_PAUSE_REPto config filev4 changes:
update and add more comments onsched_yield()v3 changes:
new patch addingsched_yield()inrte_ringto avoid long spinconfig/common_bsdapp | 1 + config/common_linuxapp | 1 + lib/librte_ring/rte_ring.h | 31 +++++++++++++++++++++++++++---- 3 files changed, 29 insertions(+), 4 deletions(-)config/common_bsdapp +0
-0
config/common_bsdapp CONFIG_RTE_PMD_PACKET_PREFETCH=y · line 237
Quoted 4 lines
config/common_bsdapp +1
-0@@ -234,6 +234,7 @@ CONFIG_RTE_PMD_PACKET_PREFETCH=y CONFIG_RTE_LIBRTE_RING=y CONFIG_RTE_LIBRTE_RING_DEBUG=n CONFIG_RTE_RING_SPLIT_PROD_CONS=n +CONFIG_RTE_RING_PAUSE_REP=n
Maybe it's better to use CONFIG_RTE_RING_PAUSE_REP=0 instead? If I understand well, it has to be set to an integer value to enable it, am I correct?
Thanks,
Olivier
A message that is not in the archive (sent off-list or not yet received): [email protected]
Re: [PATCH v5 18/19] ring: add sched_yield to avoid spin forever
Hi,
Quoted 33 lines
-----Original Message-----
From: Olivier MATZ [mailto:[email protected]]
Sent: Thursday, February 12, 2015 7:16 PM
To: Liang, Cunming; [email protected]
Cc: Ananyev, Konstantin
Subject: Re: [PATCH v5 18/19] ring: addsched_yieldto avoid spin foreverHi,
Quoted 1 line · Cunming Liang
Add a
sched_yield()syscall if the thread spins for too long, waiting other threadto finish its operations on the ring.
Quoted 1 line
That gives pre-empted thread a chance to proceed and finish with ring
enqnue/dequeue operation.
Quoted 1 line
The purpose is to reduce contention on the ring. By
ring_perf_test, it doesn'tshows additional perf penalty.
Quoted 17 lines
Signed-off-by Cunming Liang <[email protected]>---
v5 changes:
addRTE_RING_PAUSE_REPto config filev4 changes:
update and add more comments onsched_yield()v3 changes:
new patch addingsched_yield()inrte_ringto avoid long spinconfig/common_bsdapp | 1 + config/common_linuxapp | 1 + lib/librte_ring/rte_ring.h | 31 +++++++++++++++++++++++++++---- 3 files changed, 29 insertions(+), 4 deletions(-)
Quoted 13 lines
config/common_bsdapp CONFIG_RTE_PMD_PACKET_PREFETCH=y · line 237
Quoted 9 lines
config/common_bsdapp +1
-0@@ -234,6 +234,7 @@ CONFIG_RTE_PMD_PACKET_PREFETCH=y CONFIG_RTE_LIBRTE_RING=y CONFIG_RTE_LIBRTE_RING_DEBUG=n CONFIG_RTE_RING_SPLIT_PROD_CONS=n +CONFIG_RTE_RING_PAUSE_REP=nMaybe it's better to use
CONFIG_RTE_RING_PAUSE_REP=0instead? If I understand well, it has to be set to an integer value to enable it, am I correct?
[LCM] If RTE_RING_PAUSE_REP=N (no define), by default will use 0. If it's set to 'y'(=1), will issue yield in the most frequent rate. It also can set as integer to assign any number. All cases works for this configure.
One point is in configure file, just demonstrate the default way to use it.
It can't prevent to use anything unexpected. Except we rule the n & y illegal for this option.
The meaningful value of it can write in the doc.
Quoted 3 lines
Thanks,
Olivier
A message that is not in the archive (sent off-list or not yet received): D0158A423229094DA7ABF71CF2FA0DA3118D95B1-E2R4CRU6q/[email protected]
Re: [PATCH v5 18/19] ring: add sched_yield to avoid spin forever
Quoted 57 lines
-----Original Message-----
From: Liang, Cunming
Sent: Thursday, February 12, 2015 1:05 PM
To: Olivier MATZ; [email protected]
Cc: Ananyev, Konstantin
Subject: RE: [PATCH v5 18/19] ring: addsched_yieldto avoid spin foreverHi,
Quoted 33 lines
-----Original Message-----
From: Olivier MATZ [mailto:[email protected]]
Sent: Thursday, February 12, 2015 7:16 PM
To: Liang, Cunming; [email protected]
Cc: Ananyev, Konstantin
Subject: Re: [PATCH v5 18/19] ring: addsched_yieldto avoid spin foreverHi,
Quoted 1 line · Cunming Liang
Add a
sched_yield()syscall if the thread spins for too long, waiting other threadto finish its operations on the ring.
Quoted 1 line
That gives pre-empted thread a chance to proceed and finish with ring
enqnue/dequeue operation.
Quoted 1 line
The purpose is to reduce contention on the ring. By
ring_perf_test, it doesn'tshows additional perf penalty.
Quoted 17 lines
Signed-off-by Cunming Liang <[email protected]>---
v5 changes:
addRTE_RING_PAUSE_REPto config filev4 changes:
update and add more comments onsched_yield()v3 changes:
new patch addingsched_yield()inrte_ringto avoid long spinconfig/common_bsdapp | 1 + config/common_linuxapp | 1 + lib/librte_ring/rte_ring.h | 31 +++++++++++++++++++++++++++---- 3 files changed, 29 insertions(+), 4 deletions(-)Quoted 13 lines
config/common_bsdapp CONFIG_RTE_PMD_PACKET_PREFETCH=y · line 237
Quoted 9 lines
config/common_bsdapp +1
-0@@ -234,6 +234,7 @@ CONFIG_RTE_PMD_PACKET_PREFETCH=y CONFIG_RTE_LIBRTE_RING=y CONFIG_RTE_LIBRTE_RING_DEBUG=n CONFIG_RTE_RING_SPLIT_PROD_CONS=n +CONFIG_RTE_RING_PAUSE_REP=nMaybe it's better to use
CONFIG_RTE_RING_PAUSE_REP=0instead? If I understand well, it has to be set to an integer value to enable it, am I correct?
Quoted 5 lines
[LCM] If RTE_RING_PAUSE_REP=N (no define), by default will use 0. If it's set to 'y'(=1), will issue yield in the most frequent rate. It also can set as integer to assign any number. All cases works for this configure.
One point is in configure file, just demonstrate the default way to use it.
It can't prevent to use anything unexpected. Except we rule the n & y illegal for this option.
The meaningful value of it can write in the doc.
I also think that it is better avoid 'y' and 'n' (though as you said it would work), but use integers for all cases. Less confusion for the users.
Konstantin
Quoted 3 lines
Quoted 3 lines
Thanks,
Olivier
A message that is not in the archive (sent off-list or not yet received): 2601191342CEEE43887BDE71AB977258213E5500-pww93C2UFcwu0RiL9chJVbfspsVTdybXVpNB7YpNyf8@public.gmane.org
Re: [PATCH v5 18/19] ring: add sched_yield to avoid spin forever
Quoted 63 lines · Konstantin
Quoted 57 lines
-----Original Message-----
From: Liang, Cunming
Sent: Thursday, February 12, 2015 1:05 PM
To: Olivier MATZ; [email protected]
Cc: Ananyev, Konstantin
Subject: RE: [PATCH v5 18/19] ring: addsched_yieldto avoid spin foreverHi,
Quoted 33 lines
-----Original Message-----
From: Olivier MATZ [mailto:[email protected]]
Sent: Thursday, February 12, 2015 7:16 PM
To: Liang, Cunming; [email protected]
Cc: Ananyev, Konstantin
Subject: Re: [PATCH v5 18/19] ring: addsched_yieldto avoid spin foreverHi,
Quoted 1 line · Cunming Liang
Add a
sched_yield()syscall if the thread spins for too long, waiting other threadto finish its operations on the ring.
Quoted 1 line
That gives pre-empted thread a chance to proceed and finish with ring
enqnue/dequeue operation.
Quoted 1 line
The purpose is to reduce contention on the ring. By
ring_perf_test, it doesn'tshows additional perf penalty.
Quoted 17 lines
Signed-off-by Cunming Liang <[email protected]>---
v5 changes:
addRTE_RING_PAUSE_REPto config filev4 changes:
update and add more comments onsched_yield()v3 changes:
new patch addingsched_yield()inrte_ringto avoid long spinconfig/common_bsdapp | 1 + config/common_linuxapp | 1 + lib/librte_ring/rte_ring.h | 31 +++++++++++++++++++++++++++---- 3 files changed, 29 insertions(+), 4 deletions(-)Quoted 13 lines
config/common_bsdapp CONFIG_RTE_PMD_PACKET_PREFETCH=y · line 237
Quoted 9 lines
config/common_bsdapp +1
-0@@ -234,6 +234,7 @@ CONFIG_RTE_PMD_PACKET_PREFETCH=y CONFIG_RTE_LIBRTE_RING=y CONFIG_RTE_LIBRTE_RING_DEBUG=n CONFIG_RTE_RING_SPLIT_PROD_CONS=n +CONFIG_RTE_RING_PAUSE_REP=nMaybe it's better to use
CONFIG_RTE_RING_PAUSE_REP=0instead? If I understand well, it has to be set to an integer value to enable it, am I correct?Quoted 5 lines
[LCM] If RTE_RING_PAUSE_REP=N (no define), by default will use 0. If it's set to 'y'(=1), will issue yield in the most frequent rate. It also can set as integer to assign any number. All cases works for this configure.
One point is in configure file, just demonstrate the default way to use it.
It can't prevent to use anything unexpected. Except we rule the n & y illegal for this option.
The meaningful value of it can write in the doc.
Quoted 4 lines
I also think that it is better avoid 'y' and 'n' (though as you said it would work), but use integers for all cases. Less confusion for the users.
Konstantin
+1
Also expand "REP" to "REP_COUNT" to make it clear that it's a numeric value.
/Bruce
PATCH v5 19/19 timer: add support to non-EAL thread
In reply to a message not in the archiveAllow to setup timers only for EAL (lcore) threads (__lcore_id < MAX_LCORE_ID). E.g. – dynamically created thread will be able to reset/stop timer for lcore thread, but it will be not allowed to setup timer for itself or another non-lcore thread. rte_timer_manage() for non-lcore thread would simply do nothing and return straightway.
---
v5 changes:
add assert in rte_timer_manage
remove duplicate check in timer_set_config_state
lib/librte_timer/rte_timer.c | 31 ++++++++++++++++++++++--------- lib/librte_timer/rte_timer.h | 4 ++-- 2 files changed, 24 insertions(+), 11 deletions(-)
lib/librte_timer/rte_timer.c +22 -9
@@ -35,6 +35,7 @@#include <stdio.h> #include <stdint.h> #include <inttypes.h> +#include <assert.h> #include <rte_atomic.h> #include <rte_common.h>
@@ -79,9 +80,10 @@ static struct priv_timer priv_timer[RTE_MAX_LCORE];/* when debug is enabled, store some statistics */ #ifdef RTE_LIBRTE_TIMER_DEBUG -#define __TIMER_STAT_ADD (name, n) do { \ - unsigned __lcore_id = rte_lcore_id(); \ - priv_timer[__lcore_id].stats.name += (n); \ +#define __TIMER_STAT_ADD (name, n) do { \ + unsigned __lcore_id = rte_lcore_id(); \ + if (__lcore_id < RTE_MAX_LCORE) \ + priv_timer[__lcore_id].stats.name += (n); \ } while(0)#else #define __TIMER_STAT_ADD (name, n) do {} while(0)
@@ -135,7 +137,7 @@ timer_set_config_state(struct rte_timer *tim,/* timer is running on another core, exit */ if (prev_status.state ==RTE_TIMER_RUNNING && - (unsigned )prev_status.owner != lcore_id) + prev_status.owner != (uint16_t )lcore_id)return -1 ;/* timer is being configured on another core */
@@ -366,9 +368,15 @@ __rte_timer_reset(struct rte_timer *tim, uint64_t expire,/* round robin for tim_lcore */ if (tim_lcore == (unsigned )LCORE_ID_ANY ) { - tim_lcore =rte_get_next_lcore (priv_timer[lcore_id].prev_lcore, -0 ,1 ); - priv_timer[lcore_id].prev_lcore = tim_lcore; +if (lcore_id !=LCORE_ID_ANY ) { + tim_lcore =rte_get_next_lcore ( + priv_timer[lcore_id].prev_lcore, +0 ,1 ); + priv_timer[lcore_id].prev_lcore = tim_lcore; + }else +/* non-EAL thread do not run rte_timer_manage(), +* so schedule the timer on the first enabled lcore. */ + tim_lcore =rte_get_next_lcore (LCORE_ID_ANY ,0 ,1 ); }/* wait that the timer is in correct status before update,
@@ -378,7 +386,8 @@ __rte_timer_reset(struct rte_timer *tim, uint64_t expire,return -1 ;__TIMER_STAT_ADD (reset,1 ); -if (prev_status.state ==RTE_TIMER_RUNNING ) { +if (prev_status.state ==RTE_TIMER_RUNNING && + lcore_id !=LCORE_ID_ANY ) { priv_timer[lcore_id].updated =1 ; }
@@ -455,7 +464,8 @@ rte_timer_stop(struct rte_timer *tim)return -1 ;__TIMER_STAT_ADD (stop,1 ); -if (prev_status.state ==RTE_TIMER_RUNNING ) { +if (prev_status.state ==RTE_TIMER_RUNNING && + lcore_id !=LCORE_ID_ANY ) { priv_timer[lcore_id].updated =1 ; }
@@ -499,6 +509,9 @@ void rte_timer_manage(void)uint64_t cur_time;int i, ret; +/* timer manager only runs on EAL thread */ +assert (lcore_id !=LCORE_ID_ANY ); +__TIMER_STAT_ADD (manage,1 );/* optimize for the case where per-cpu list is empty */ if (priv_timer[lcore_id].pending_head.sl_next[0 ] ==NULL )
lib/librte_timer/rte_timer.h +2 -2
@@ -76,7 +76,7 @@ extern "C" {#define RTE_TIMER_RUNNING 2/**< State: timer function is running. */ #define RTE_TIMER_CONFIG 3/**< State: timer is being configured. */ -#define RTE_TIMER_NO_OWNER -1/**< Timer has no owner. */ +#define RTE_TIMER_NO_OWNER -2/**< Timer has no owner. */ /** * Timer type: Periodic or single (one-shot).
@@ -310,7 +310,7 @@ int rte_timer_pending(struct rte_timer *tim);/** * Manage the timer list and execute callback functions. * -* This function must be called periodically from all cores +* This function must be called periodically from EAL lcores * main_loop(). It browses the list of pending timers and runs all * timers that are expired. *
Signature · 1 line
1.8.1.4
A message that is not in the archive (sent off-list or not yet received): 1423728996-3004-20-git-send-email-cunming.liang-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org
Re: [PATCH v5 19/19] timer: add support to non-EAL thread
Hi lads,
Quoted 87 lines
-----Original Message-----
From: Liang, Cunming
Sent: Thursday, February 12, 2015 8:17 AM
To: [email protected]
Cc: Ananyev, Konstantin; [email protected]; Liang, Cunming
Subject: [PATCH v5 19/19] timer: add support to non-EAL threadAllow to setup timers only for EAL (lcore) threads (
__lcore_id<MAX_LCORE_ID). E.g. – dynamically created thread will be able to reset/stop timer for lcore thread, but it will be not allowed to setup timer for itself or another non-lcore thread.rte_timer_manage()for non-lcore thread would simply do nothing and return straightway.Signed-off-by Cunming Liang <[email protected]>---
v5 changes:
add assert inrte_timer_manage
remove duplicate check intimer_set_config_statelib/librte_timer/rte_timer.c | 31 ++++++++++++++++++++++--------- lib/librte_timer/rte_timer.h | 4 ++-- 2 files changed, 24 insertions(+), 11 deletions(-)lib/librte_timer/rte_timer.c +17
-8@@ -35,6 +35,7 @@#include <stdio.h> #include <stdint.h> #include <inttypes.h> +#include <assert.h> #include <rte_atomic.h> #include <rte_common.h> @@ -79,9 +80,10 @@ static struct priv_timer priv_timer[RTE_MAX_LCORE];/* when debug is enabled, store some statistics */ #ifdef RTE_LIBRTE_TIMER_DEBUG -#define __TIMER_STAT_ADD (name, n) do { \ - unsigned __lcore_id = rte_lcore_id(); \ - priv_timer[__lcore_id].stats.name += (n); \ +#define __TIMER_STAT_ADD (name, n) do { \ + unsigned __lcore_id = rte_lcore_id(); \ + if (__lcore_id < RTE_MAX_LCORE) \ + priv_timer[__lcore_id].stats.name += (n); \ } while(0)#else #define __TIMER_STAT_ADD (name, n) do {} while(0)@@ -135,7 +137,7 @@ timer_set_config_state(struct rte_timer *tim,/* timer is running on another core, exit */ if (prev_status.state ==RTE_TIMER_RUNNING && - (unsigned )prev_status.owner != lcore_id) + prev_status.owner != (uint16_t )lcore_id)return -1 ;/* timer is being configured on another core */ @@ -366,9 +368,15 @@ __rte_timer_reset(struct rte_timer *tim, uint64_t expire,/* round robin for tim_lcore */ if (tim_lcore == (unsigned )LCORE_ID_ANY ) { - tim_lcore =rte_get_next_lcore (priv_timer[lcore_id].prev_lcore, -0 ,1 ); - priv_timer[lcore_id].prev_lcore = tim_lcore; +if (lcore_id !=LCORE_ID_ANY ) { + tim_lcore =rte_get_next_lcore ( + priv_timer[lcore_id].prev_lcore, +0 ,1 ); + priv_timer[lcore_id].prev_lcore = tim_lcore; + }else +/* non-EAL thread do not run rte_timer_manage(), +* so schedule the timer on the first enabled lcore. */ + tim_lcore =rte_get_next_lcore (LCORE_ID_ANY ,0 ,1 ); }/* wait that the timer is in correct status before update, @@ -378,7 +386,8 @@ __rte_timer_reset(struct rte_timer *tim, uint64_t expire,return -1 ;__TIMER_STAT_ADD (reset,1 ); -if (prev_status.state ==RTE_TIMER_RUNNING ) { +if (prev_status.state ==RTE_TIMER_RUNNING && + lcore_id !=LCORE_ID_ANY ) { priv_timer[lcore_id].updated =1 ; }
lib/librte_timer/rte_timer.c rte_timer_stop(struct rte_timer *tim) · line 470
Quoted 8 lines
lib/librte_timer/rte_timer.c +2
-1@@ -455,7 +464,8 @@ rte_timer_stop(struct rte_timer *tim)return -1 ;__TIMER_STAT_ADD (stop,1 ); -if (prev_status.state ==RTE_TIMER_RUNNING ) { +if (prev_status.state ==RTE_TIMER_RUNNING && + lcore_id !=LCORE_ID_ANY ) { priv_timer[lcore_id].updated =1 ; }
About ' lcore_id != LCORE_ID_ANY' vs ' lcore_id < RTE_MAX_LCORE'.
I think both ways are valid right now.
Though using ' lcore_id != LCORE_ID_ANY' means, that if user will setup PER_LCORE(_lcore_id) for dynamically created thread to some value >= RTE_MAX_LCORE, then our code will not work properly.
Konstantin
Quoted 35 lines
lib/librte_timer/rte_timer.c +3
-0@@ -499,6 +509,9 @@ void rte_timer_manage(void)uint64_t cur_time;int i, ret; +/* timer manager only runs on EAL thread */ +assert (lcore_id !=LCORE_ID_ANY ); +__TIMER_STAT_ADD (manage,1 );/* optimize for the case where per-cpu list is empty */ if (priv_timer[lcore_id].pending_head.sl_next[0 ] ==NULL )lib/librte_timer/rte_timer.h +2
-3@@ -76,7 +76,7 @@ extern "C" {#define RTE_TIMER_RUNNING 2/**< State: timer function is running. */ #define RTE_TIMER_CONFIG 3/**< State: timer is being configured. */ -#define RTE_TIMER_NO_OWNER -1/**< Timer has no owner. */ +#define RTE_TIMER_NO_OWNER -2/**< Timer has no owner. */ /** * Timer type: Periodic or single (one-shot). @@ -310,7 +310,7 @@ int rte_timer_pending(struct rte_timer *tim);/** * Manage the timer list and execute callback functions. * -* This function must be called periodically from all cores +* This function must be called periodically from EAL lcores * main_loop(). It browses the list of pending timers and runs all * timers that are expired. * -- 1.8.1.4
A message that is not in the archive (sent off-list or not yet received): 2601191342CEEE43887BDE71AB977258213E5585-pww93C2UFcwu0RiL9chJVbfspsVTdybXVpNB7YpNyf8@public.gmane.org
Re: [PATCH v5 19/19] timer: add support to non-EAL thread
Quoted 105 lines
-----Original Message-----
From: Ananyev, Konstantin
Sent: Thursday, February 12, 2015 9:54 PM
To: Liang, Cunming; [email protected]
Cc: [email protected]
Subject: RE: [PATCH v5 19/19] timer: add support to non-EAL threadHi lads,
Quoted 8 lines
-----Original Message-----
From: Liang, Cunming
Sent: Thursday, February 12, 2015 8:17 AM
To: [email protected]
Cc: Ananyev, Konstantin; [email protected]; Liang, Cunming
Subject: [PATCH v5 19/19] timer: add support to non-EAL threadAllow to setup timers only for EAL (lcore) threads (
__lcore_id<
MAX_LCORE_ID).Quoted 1 line
E.g. – dynamically created thread will be able to reset/stop timer for lcore
thread,
Quoted 2 lines
but it will be not allowed to setup timer for itself or another non-lcore thread.
rte_timer_manage()for non-lcore thread would simply do nothing and returnstraightway.
lib/librte_timer/rte_timer.c __rte_timer_reset(struct rte_timer *tim, uint64_t
Quoted 47 lines
Signed-off-by Cunming Liang <[email protected]>---
v5 changes:
add assert inrte_timer_manage
remove duplicate check intimer_set_config_statelib/librte_timer/rte_timer.c | 31 ++++++++++++++++++++++--------- lib/librte_timer/rte_timer.h | 4 ++-- 2 files changed, 24 insertions(+), 11 deletions(-)lib/librte_timer/rte_timer.c +6
-4@@ -35,6 +35,7 @@#include <stdio.h> #include <stdint.h> #include <inttypes.h> +#include <assert.h> #include <rte_atomic.h> #include <rte_common.h> @@ -79,9 +80,10 @@ static struct priv_timer priv_timer[RTE_MAX_LCORE];/* when debug is enabled, store some statistics */ #ifdef RTE_LIBRTE_TIMER_DEBUG -#define __TIMER_STAT_ADD (name, n) do { \ - unsigned __lcore_id = rte_lcore_id(); \ - priv_timer[__lcore_id].stats.name += (n); \ +#define __TIMER_STAT_ADD (name, n) do { \ + unsigned __lcore_id = rte_lcore_id(); \ + if (__lcore_id < RTE_MAX_LCORE) \ + priv_timer[__lcore_id].stats.name += (n); \ } while(0)#else #define __TIMER_STAT_ADD (name, n) do {} while(0)@@ -135,7 +137,7 @@ timer_set_config_state(struct rte_timer *tim,/* timer is running on another core, exit */ if (prev_status.state ==RTE_TIMER_RUNNING && - (unsigned )prev_status.owner != lcore_id) + prev_status.owner != (uint16_t )lcore_id)return -1 ;/* timer is being configured on another core */ @@ -366,9 +368,15 @@ __rte_timer_reset(struct rte_timer *tim, uint64_texpire,
lib/librte_timer/rte_timer.c __rte_timer_reset(struct rte_timer *tim, uint64_t
Quoted 19 lines
lib/librte_timer/rte_timer.c +9
-3/* round robin for tim_lcore */ if (tim_lcore == (unsigned )LCORE_ID_ANY ) { - tim_lcore =rte_get_next_lcore (priv_timer[lcore_id].prev_lcore, -0 ,1 ); - priv_timer[lcore_id].prev_lcore = tim_lcore; +if (lcore_id !=LCORE_ID_ANY ) { + tim_lcore =rte_get_next_lcore ( + priv_timer[lcore_id].prev_lcore, +0 ,1 ); + priv_timer[lcore_id].prev_lcore = tim_lcore; + }else +/* non-EAL thread do not run rte_timer_manage(), +* so schedule the timer on the first enabled lcore. */ + tim_lcore =rte_get_next_lcore (LCORE_ID_ANY ,0 ,1 ); }/* wait that the timer is in correct status before update, @@ -378,7 +386,8 @@ __rte_timer_reset(struct rte_timer *tim, uint64_texpire,
Quoted 12 lines
lib/librte_timer/rte_timer.c +2
-1return -1 ;__TIMER_STAT_ADD (reset,1 ); -if (prev_status.state ==RTE_TIMER_RUNNING ) { +if (prev_status.state ==RTE_TIMER_RUNNING && + lcore_id !=LCORE_ID_ANY ) { priv_timer[lcore_id].updated =1 ; }@@ -455,7 +464,8 @@ rte_timer_stop(struct rte_timer *tim)return -1 ;
Quoted 14 lines
lib/librte_timer/rte_timer.c rte_timer_stop(struct rte_timer *tim) · line 470
Quoted 6 lines
lib/librte_timer/rte_timer.c +2
-1__TIMER_STAT_ADD (stop,1 ); -if (prev_status.state ==RTE_TIMER_RUNNING ) { +if (prev_status.state ==RTE_TIMER_RUNNING && + lcore_id !=LCORE_ID_ANY ) { priv_timer[lcore_id].updated =1 ; }About '
lcore_id!=LCORE_ID_ANY' vs 'lcore_id<RTE_MAX_LCORE'. I think both ways are valid right now.
Though using 'lcore_id!=LCORE_ID_ANY' means, that if user will setupPER_LCORE(_lcore_id)for dynamically created thread to some value >=RTE_MAX_LCORE,
then our code will not work properly.
Konstantin
[LCM] Ok, now we get the agreement as below.
1. only using '< RTE_MAX_LCORE' to check the EAL thread with valid lcore_id.
2. LCORE_ID_ANY is used as lcore_id default value or used for any unspecified lcore_id assignment.
Quoted 36 lines
Quoted 36 lines
lib/librte_timer/rte_timer.c +3
-0@@ -499,6 +509,9 @@ void rte_timer_manage(void)uint64_t cur_time;int i, ret; +/* timer manager only runs on EAL thread */ +assert (lcore_id !=LCORE_ID_ANY ); +__TIMER_STAT_ADD (manage,1 );/* optimize for the case where per-cpu list is empty */ if (priv_timer[lcore_id].pending_head.sl_next[0 ] ==NULL )lib/librte_timer/rte_timer.h +2
-3@@ -76,7 +76,7 @@ extern "C" {#define RTE_TIMER_RUNNING 2/**< State: timer function is running. */ #define RTE_TIMER_CONFIG 3/**< State: timer is being configured. */ -#define RTE_TIMER_NO_OWNER -1/**< Timer has no owner. */ +#define RTE_TIMER_NO_OWNER -2/**< Timer has no owner. */ /** * Timer type: Periodic or single (one-shot). @@ -310,7 +310,7 @@ int rte_timer_pending(struct rte_timer *tim);/** * Manage the timer list and execute callback functions. * -* This function must be called periodically from all cores +* This function must be called periodically from EAL lcores * main_loop(). It browses the list of pending timers and runs all * timers that are expired. * -- 1.8.1.4
A message that is not in the archive (sent off-list or not yet received): D0158A423229094DA7ABF71CF2FA0DA3118D97A2-E2R4CRU6q/[email protected]
Re: [PATCH v5 19/19] timer: add support to non-EAL thread
Hi,
Quoted 10 lines · Cunming
Quoted 7 lines
About '
lcore_id!=LCORE_ID_ANY' vs 'lcore_id<RTE_MAX_LCORE'. I think both ways are valid right now.
Though using 'lcore_id!=LCORE_ID_ANY' means, that if user will setupPER_LCORE(_lcore_id)for dynamically created thread to some value >=RTE_MAX_LCORE,
then our code will not work properly.
Konstantin[LCM] Ok, now we get the agreement as below.
1. only using '<RTE_MAX_LCORE' to check the EAL thread with validlcore_id.
2.LCORE_ID_ANYis used aslcore_iddefault value or used for any unspecifiedlcore_idassignment.
Doing like this is fine for me, although I don't really agree with the initial argument: it's should not be allowed for an application to modify an eal variable (_lcore_id).
Regards,
Olivier
v6 cover support multi-pthread per core
In reply to a message not in the archivev6 changes:
rename RTE_RING_PAUSE_REP(_COUNT) and set default to 0 rollback to use RTE_MAX_LCORE when checking valid lcore_id for EAL thread
v5 changes:
reorder some patch and split into addtional two patches rte_thread_get_affinity() return type change to avoid add RTE_RING_PAUSE_REP into config and by default turn off
v4 changes:
new patch fixing strnlen() invalid return in 32bit icc [03/17] update and add more comments on sched_yield() [16/17]
v3 changes:
new patch adding sched_yield() in rte_ring to avoid long spin [16/17]
v2 changes:
add '<number>-<number>' support for EAL option '--lcores' [02/17]
The patch series contain the enhancements of EAL and fixes for libraries
to run multi-pthreads(either EAL or non-EAL thread) per physical core.
Two major changes list as below:
- Extend the core affinity of each EAL thread to 1:n.
Each lcore stands for a EAL thread rather than a logical core.
The change adds new EAL option to allow static lcore to cpuset assginment. Then a lcore(EAL thread) affinity to a cpuset, original 1:1 mapping is the special case.
- Fix the libraries to allow running on any non-EAL thread.
It fix the gaps running libraries in non-EAL thread(dynamic created by user). Each fix libraries take care the case of rte_lcore_id() >= RTE_MAX_LCORE.
Thanks a million for the comments from Konstantin, Bruce, Mirek and Stephen in RFC review.
Cunming Liang (19):
eal: add cpuset into per EAL thread lcore_config
eal: fix PAGE_SIZE redefine complaint on freebsd
eal: new eal option '--lcores' for cpu assignment
eal: fix wrong strnlen() return value in 32bit icc
eal: add support parsing socket_id from cpuset
eal: new TLS definition and API declaration
eal: add eal_common_thread.c for common thread API
eal: standardize init sequence between linux and bsd
eal: add rte_gettid() to acquire unique system tid
eal: apply affinity of EAL thread by assigned cpuset
enic: fix re-define freebsd compile complain
malloc: fix the issue of SOCKET_ID_ANY
log: fix the gap to support non-EAL thread
eal: set _lcore_id and _socket_id to (-1) by default
eal: fix recursive spinlock in non-EAL thraed
mempool: add support to non-EAL thread
ring: add support to non-EAL thread
ring: add sched_yield to avoid spin forever
timer: add support to non-EAL thread
config/common_bsdapp | 1 + config/common_linuxapp | 1 + lib/librte_eal/bsdapp/eal/Makefile | 1 + lib/librte_eal/bsdapp/eal/eal.c | 14 +- lib/librte_eal/bsdapp/eal/eal_lcore.c | 14 + lib/librte_eal/bsdapp/eal/eal_memory.c | 8 +- lib/librte_eal/bsdapp/eal/eal_thread.c | 77 ++---- lib/librte_eal/common/eal_common_log.c | 17 +- lib/librte_eal/common/eal_common_options.c | 308 ++++++++++++++++++++- lib/librte_eal/common/eal_common_thread.c | 150 ++++++++++ lib/librte_eal/common/eal_options.h | 2 + lib/librte_eal/common/eal_thread.h | 47 ++++ .../common/include/generic/rte_spinlock.h | 4 +- lib/librte_eal/common/include/rte_eal.h | 27 ++ lib/librte_eal/common/include/rte_lcore.h | 40 ++- lib/librte_eal/common/include/rte_log.h | 5 + lib/librte_eal/linuxapp/eal/Makefile | 4 + lib/librte_eal/linuxapp/eal/eal.c | 8 +- lib/librte_eal/linuxapp/eal/eal_lcore.c | 15 +- lib/librte_eal/linuxapp/eal/eal_thread.c | 77 ++---- lib/librte_malloc/malloc_heap.h | 7 +- lib/librte_mempool/rte_mempool.h | 18 +- lib/librte_pmd_enic/enic.h | 4 +- lib/librte_pmd_enic/enic_compat.h | 2 +- lib/librte_pmd_enic/vnic/vnic_dev.c | 6 +- lib/librte_ring/rte_ring.h | 41 ++- lib/librte_timer/rte_timer.c | 32 ++- lib/librte_timer/rte_timer.h | 4 +- 28 files changed, 765 insertions(+), 169 deletions(-) create mode 100644 lib/librte_eal/common/eal_common_thread.c
Signature · 1 line
1.8.1.4
A message that is not in the archive (sent off-list or not yet received): 1423791501-1555-1-git-send-email-cunming.liang-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org
PATCH v6 1/19 eal: add cpuset into per EAL thread lcore_config
The patch adds 'cpuset' into per-lcore configure 'lcore_config[]', as the lcore no longer always 1:1 pinning with physical cpu. The lcore now stands for a EAL thread rather than a logical cpu.
It doesn't change the default behavior of 1:1 mapping, but allows to affinity the EAL thread to multiple cpus.
---
v5 changes:
separate eal_memory.c to the new patch
lib/librte_eal/bsdapp/eal/eal_lcore.c | 7 +++++++ lib/librte_eal/common/include/rte_lcore.h | 8 ++++++++ lib/librte_eal/linuxapp/eal/Makefile | 1 + lib/librte_eal/linuxapp/eal/eal_lcore.c | 8 ++++++++ 4 files changed, 24 insertions(+)
lib/librte_eal/bsdapp/eal/eal_lcore.c +7 -0
@@ -76,11 +76,18 @@ rte_eal_cpu_init(void)* ones and enable them by default. */ for (lcore_id =0 ; lcore_id <RTE_MAX_LCORE ; lcore_id++) { +/* init cpuset for per lcore config */ +CPU_ZERO (&lcore_config[lcore_id].cpuset); + lcore_config[lcore_id].detected = (lcore_id < ncpus);if (lcore_config[lcore_id].detected ==0 ) { config->lcore_role[lcore_id] =ROLE_OFF ;continue ; } + +/* By default, lcore 1:1 map to cpu id */ +CPU_SET (lcore_id, &lcore_config[lcore_id].cpuset); +/* By default, each detected core is enabled */ config->lcore_role[lcore_id] =ROLE_RTE ; lcore_config[lcore_id].core_id =cpu_core_id (lcore_id);
lib/librte_eal/common/include/rte_lcore.h +8 -0
@@ -50,6 +50,13 @@ extern "C" {#define LCORE_ID_ANY -1/**< Any lcore. */ +#if defined(__linux__) +typedef cpu_set_t rte_cpuset_t ; +#elif defined(__FreeBSD__) +#include <pthread_np.h> +typedef cpuset_t rte_cpuset_t ; +#endif +/** * Structure storing internal configuration (per-lcore) */
@@ -65,6 +72,7 @@ struct lcore_config {unsigned socket_id;/**< physical socket id for this lcore */ unsigned core_id;/**< core number on socket for this lcore */ int core_index;/**< relative index, starting from 0 */ +rte_cpuset_t cpuset;/**< cpu set which the lcore affinity to */ };/**
lib/librte_eal/linuxapp/eal/Makefile +1 -0
@@ -91,6 +91,7 @@ SRCS-$(CONFIG_RTE_LIBRTE_EAL_LINUXAPP) += eal_common_dev.c SRCS-$(CONFIG_RTE_LIBRTE_EAL_LINUXAPP) += eal_common_options.c CFLAGS_eal.o := -D_GNU_SOURCE +CFLAGS_eal_lcore.o := -D_GNU_SOURCE CFLAGS_eal_thread.o := -D_GNU_SOURCE CFLAGS_eal_log.o := -D_GNU_SOURCE CFLAGS_eal_common_log.o := -D_GNU_SOURCE
lib/librte_eal/linuxapp/eal/eal_lcore.c +8 -0
@@ -158,11 +158,19 @@ rte_eal_cpu_init(void)* ones and enable them by default. */ for (lcore_id =0 ; lcore_id <RTE_MAX_LCORE ; lcore_id++) { +/* init cpuset for per lcore config */ +CPU_ZERO (&lcore_config[lcore_id].cpuset); + +/* in 1:1 mapping, record related cpu detected state */ lcore_config[lcore_id].detected =cpu_detected (lcore_id);if (lcore_config[lcore_id].detected ==0 ) { config->lcore_role[lcore_id] =ROLE_OFF ;continue ; } + +/* By default, lcore 1:1 map to cpu id */ +CPU_SET (lcore_id, &lcore_config[lcore_id].cpuset); +/* By default, each detected core is enabled */ config->lcore_role[lcore_id] =ROLE_RTE ; lcore_config[lcore_id].core_id =cpu_core_id (lcore_id);
Signature · 1 line
1.8.1.4
PATCH v6 2/19 eal: fix PAGE_SIZE redefine complaint on freebsd
In reply to a message not in the archive--- lib/librte_eal/bsdapp/eal/eal_memory.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-)
lib/librte_eal/bsdapp/eal/eal_memory.c +5 -3
@@ -45,7 +45,7 @@#include "eal_internal_cfg.h" #include "eal_filesystem.h" -#define PAGE_SIZE (sysconf(_SC_PAGESIZE)) +#define EAL_PAGE_SIZE (sysconf(_SC_PAGESIZE))/* * Get physical address of any mapped virtual address in the current process.
@@ -93,7 +93,8 @@ rte_eal_contigmem_init(void)char physaddr_str[64 ]; addr =mmap (NULL , hpi->hugepage_sz,PROT_READ |PROT_WRITE , -MAP_SHARED , hpi->lock_descriptor, j *PAGE_SIZE ); +MAP_SHARED , hpi->lock_descriptor, + j *EAL_PAGE_SIZE );if (addr ==MAP_FAILED ) {RTE_LOG (ERR ,EAL ,"Failed to mmap buffer %u from %s\n" , j, hpi->hugedir);
@@ -167,7 +168,8 @@ rte_eal_contigmem_attach(void)struct rte_memseg *seg = &mcfg->memseg[i]; addr =mmap (seg->addr, hpi->hugepage_sz,PROT_READ |PROT_WRITE , -MAP_SHARED |MAP_FIXED , fd_hugepage, i *PAGE_SIZE ); +MAP_SHARED |MAP_FIXED , fd_hugepage, + i *EAL_PAGE_SIZE );if (addr ==MAP_FAILED || addr != seg->addr) {RTE_LOG (ERR ,EAL ,"Failed to mmap buffer %u from %s\n" , i, hpi->hugedir);
Signature · 1 line
1.8.1.4
PATCH v6 3/19 eal: new eal option '--lcores' for cpu assignment
In reply to a message not in the archiveIt supports one new eal long option '--lcores' for EAL thread cpuset assignment.
The format pattern:
--lcores='lcores[@cpus]<,lcores[@cpus]>'
lcores, cpus could be a single digit/range or a group. '(' and ')' are necessary if it's a group.
If not supply '@cpus', the value of cpus uses the same as lcores.
e.g. '1,2@(5-7),(3-5)@(0,2),(0,6),7-8' means starting 9 EAL thread as below
lcore 0 runs on cpuset 0x41 (cpu 0,6)
lcore 1 runs on cpuset 0x2 (cpu 1)
lcore 2 runs on cpuset 0xe0 (cpu 5,6,7)
lcore 3,4,5 runs on cpuset 0x5 (cpu 0,2)
lcore 6 runs on cpuset 0x41 (cpu 0,6)
lcore 7 runs on cpuset 0x80 (cpu 7)
lcore 8 runs on cpuset 0x100 (cpu 8)
---
v5 changes:
add more comments for eal_parse_set
fix some typo
remove inline prefix from convert_to_cpuset() fix a bug introduced on v2 which broke case '(0,6)'
v2 changes:
add '<number>-<number>' support for EAL option '--lcores'
lib/librte_eal/common/eal_common_options.c | 304 ++++++++++++++++++++++++++++- lib/librte_eal/common/eal_options.h | 2 + lib/librte_eal/linuxapp/eal/Makefile | 1 + 3 files changed, 303 insertions(+), 4 deletions(-)
lib/librte_eal/common/eal_common_options.c +300 -4
@@ -45,6 +45,7 @@#include <rte_lcore.h> #include <rte_version.h> #include <rte_devargs.h> +#include <rte_memcpy.h> #include "eal_internal_cfg.h" #include "eal_options.h"
@@ -85,6 +86,7 @@ eal_long_options[] = { {OPT_XEN_DOM0, 0, 0, OPT_XEN_DOM0_NUM}, {OPT_CREATE_UIO_DEV, 1, NULL, OPT_CREATE_UIO_DEV_NUM}, {OPT_VFIO_INTR, 1, NULL, OPT_VFIO_INTR_NUM}, + {OPT_LCORES, 1, 0, OPT_LCORES_NUM}, {0, 0, 0, 0} };
@@ -255,9 +257,11 @@ eal_parse_corelist(const char *corelist)if (min ==RTE_MAX_LCORE ) min = idx;for (idx = min; idx <= max; idx++) { - cfg->lcore_role[idx] =ROLE_RTE ; - lcore_config[idx].core_index = count; - count++; +if (cfg->lcore_role[idx] !=ROLE_RTE ) { + cfg->lcore_role[idx] =ROLE_RTE ; + lcore_config[idx].core_index = count; + count++; + } } min =RTE_MAX_LCORE ; }else
@@ -292,6 +296,283 @@ eal_parse_master_lcore(const char *arg)return 0 ; } +/* +* Parse elem, the elem could be single number/range or '(' ')' group +* 1) A single number elem, it's just a simple digit. e.g. 9 +* 2) A single range elem, two digits with a '-' between. e.g. 2-6 +* 3) A group elem, combines multiple 1) or 2) with '( )'. e.g (0,2-4,6) +* Within group elem, '-' used for a range separator; +* ',' used for a single number. +*/ +static int +eal_parse_set (const char *input,uint16_t set[],unsigned num) +{ +unsigned idx; +const char *str = input; +char *end =NULL ; +unsigned min, max; + +memset (set,0 , num *sizeof (uint16_t )); + +while (isblank (*str)) + str++; + +/* only digit or left bracket is qualify for start point */ +if ((!isdigit (*str) && *str !='(' ) || *str =='\0' ) +return -1 ; + +/* process single number or single range of number */ +if (*str !='(' ) { + errno =0 ; + idx =strtoul (str, &end,10 ); +if (errno || end ==NULL || idx >= num) +return -1 ; +else { +while (isblank (*end)) + end++; + + min = idx; + max = idx; +if (*end =='-' ) { +/* process single <number>-<number> */ + end++; +while (isblank (*end)) + end++; +if (!isdigit (*end)) +return -1 ; + + errno =0 ; + idx =strtoul (end, &end,10 ); +if (errno || end ==NULL || idx >= num) +return -1 ; + max = idx; +while (isblank (*end)) + end++; +if (*end !=',' && *end !='\0' ) +return -1 ; + } + +if (*end !=',' && *end !='\0' && + *end !='@' ) +return -1 ; + +for (idx =RTE_MIN (min, max); + idx <=RTE_MAX (min, max); idx++) + set[idx] =1 ; + +return end - input; + } + } + +/* process set within bracket */ + str++; +while (isblank (*str)) + str++; +if (*str =='\0' ) +return -1 ; + + min =RTE_MAX_LCORE ; +do { + +/* go ahead to the first digit */ +while (isblank (*str)) + str++; +if (!isdigit (*str)) +return -1 ; + +/* get the digit value */ + errno =0 ; + idx =strtoul (str, &end,10 ); +if (errno || end ==NULL || idx >= num) +return -1 ; + +/* go ahead to separator '-',',' and ')' */ +while (isblank (*end)) + end++; +if (*end =='-' ) { +if (min ==RTE_MAX_LCORE ) + min = idx; +else /* avoid continuous '-' */ +return -1 ; + }else if ((*end ==',' ) || (*end ==')' )) { + max = idx; +if (min ==RTE_MAX_LCORE ) + min = idx; +for (idx =RTE_MIN (min, max); + idx <=RTE_MAX (min, max); idx++) + set[idx] =1 ; + + min =RTE_MAX_LCORE ; + }else +return -1 ; + + str = end +1 ; + }while (*end !='\0' && *end !=')' ); + +return str - input; +} + +/* convert from set array to cpuset bitmap */ +static int +convert_to_cpuset (rte_cpuset_t *cpusetp, +uint16_t *set,unsigned num) +{ +unsigned idx; + +CPU_ZERO (cpusetp); + +for (idx =0 ; idx < num; idx++) { +if (!set[idx]) +continue ; + +if (!lcore_config[idx].detected) { +RTE_LOG (ERR ,EAL ,"core %u " +"unavailable\n" , idx); +return -1 ; + } + +CPU_SET (idx, cpusetp); + } + +return 0 ; +} + +/* +* The format pattern: --lcores='lcores[@cpus]<,lcores[@cpus]>' +* lcores, cpus could be a single digit/range or a group. +* '(' and ')' are necessary if it's a group. +* If not supply '@cpus', the value of cpus uses the same as lcores. +* e.g. '1,2@(5-7),(3-5)@(0,2),(0,6),7-8' means start 9 EAL thread as below +* lcore 0 runs on cpuset 0x41 (cpu 0,6) +* lcore 1 runs on cpuset 0x2 (cpu 1) +* lcore 2 runs on cpuset 0xe0 (cpu 5,6,7) +* lcore 3,4,5 runs on cpuset 0x5 (cpu 0,2) +* lcore 6 runs on cpuset 0x41 (cpu 0,6) +* lcore 7 runs on cpuset 0x80 (cpu 7) +* lcore 8 runs on cpuset 0x100 (cpu 8) +*/ +static int +eal_parse_lcores (const char *lcores) +{ +struct rte_config *cfg =rte_eal_get_configuration (); +static uint16_t set[RTE_MAX_LCORE ]; +unsigned idx =0 ; +int i; +unsigned count =0 ; +const char *lcore_start =NULL ; +const char *end =NULL ; +int offset; +rte_cpuset_t cpuset; +int lflags =0 ; +int ret =-1 ; + +if (lcores ==NULL ) +return -1 ; + +/* Remove all blank characters ahead and after */ +while (isblank (*lcores)) + lcores++; + i =strnlen (lcores,sysconf (_SC_ARG_MAX)); +while ((i >0 ) &&isblank (lcores[i -1 ])) + i--; + +CPU_ZERO (&cpuset); + +/* Reset lcore config */ +for (idx =0 ; idx <RTE_MAX_LCORE ; idx++) { + cfg->lcore_role[idx] =ROLE_OFF ; + lcore_config[idx].core_index =-1 ; +CPU_ZERO (&lcore_config[idx].cpuset); + } + +/* Get list of cores */ +do { +while (isblank (*lcores)) + lcores++; +if (*lcores =='\0' ) + goto err; + +/* record lcore_set start point */ + lcore_start = lcores; + +/* go across a complete bracket */ +if (*lcore_start =='(' ) { + lcores +=strcspn (lcores,")" ); +if (*lcores++ =='\0' ) + goto err; + } + +/* scan the separator '@', ','(next) or '\0'(finish) */ + lcores +=strcspn (lcores,"@," ); + +if (*lcores =='@' ) { +/* explict assign cpu_set */ + offset =eal_parse_set (lcores +1 , set,RTE_DIM (set)); +if (offset <0 ) + goto err; + +/* prepare cpu_set and update the end cursor */ +if (0 >convert_to_cpuset (&cpuset, + set,RTE_DIM (set))) + goto err; + end = lcores +1 + offset; + }else {/* ',' or '\0' */ +/* haven't given cpu_set, current loop done */ + end = lcores; + +/* go back to check <number>-<number> */ + offset =strcspn (lcore_start,"(-" ); +if (offset < (end - lcore_start) && + *(lcore_start + offset) !='(' ) + lflags =1 ; + } + +if (*end !=',' && *end !='\0' ) + goto err; + +/* parse lcore_set from start point */ +if (0 >eal_parse_set (lcore_start, set,RTE_DIM (set))) + goto err; + +/* without '@', by default using lcore_set as cpu_set */ +if (*lcores !='@' && +0 >convert_to_cpuset (&cpuset, set,RTE_DIM (set))) + goto err; + +/* start to update lcore_set */ +for (idx =0 ; idx <RTE_MAX_LCORE ; idx++) { +if (!set[idx]) +continue ; + +if (cfg->lcore_role[idx] !=ROLE_RTE ) { + lcore_config[idx].core_index = count; + cfg->lcore_role[idx] =ROLE_RTE ; + count++; + } + +if (lflags) { +CPU_ZERO (&cpuset); +CPU_SET (idx, &cpuset); + } +rte_memcpy (&lcore_config[idx].cpuset, &cpuset, +sizeof (rte_cpuset_t)); + } + + lcores = end +1 ; + }while (*end !='\0' ); + +if (count ==0 ) + goto err; + + cfg->lcore_count = count; + lcores_parsed =1 ; + ret =0 ; + +err: + +return ret; +} +static int eal_parse_syslog (const char *facility,struct internal_config *conf) {
@@ -492,6 +773,13 @@ eal_parse_common_option(int opt, const char *optarg, conf->log_level = log;break ; } +case OPT_LCORES_NUM : +if (eal_parse_lcores (optarg) <0 ) { +RTE_LOG (ERR ,EAL ,"invalid parameter for --" +OPT_LCORES "\n" ); +return -1 ; + } +break ;/* don't know what to do, leave this to caller */ default :
@@ -530,7 +818,7 @@ eal_check_common_options(struct internal_config *internal_cfg)if (!lcores_parsed) {RTE_LOG (ERR ,EAL ,"CPU cores must be enabled with options " -"-c or -l\n" ); +"-c, -l or --lcores\n" );return -1 ; }if (cfg->lcore_role[cfg->master_lcore] !=ROLE_RTE ) {
@@ -586,6 +874,14 @@ eal_common_usage(void)" The argument format is <c1>[-c2][,c3[-c4],...]\n" " where c1, c2, etc are core indexes between 0 and %d\n" " --" OPT_MASTER_LCORE " ID: Core ID that is used as master\n" +" --" OPT_LCORES " MAP: maps between lcore_set to phys_cpu_set\n" +" The argument format is\n" +" 'lcores[@cpus]<,lcores[@cpus],...>'\n" +" lcores and cpus list are grouped by '(' and ')'\n" +" Within the group, '-' is used for range separator,\n" +" ',' is used for single number separator.\n" +" '( )' can be omitted for single element group, '@' \n" +" can be omitted if cpus and lcores has the same value\n" " -n NUM : Number of memory channels\n" " -v : Display version information on startup\n" " -m MB : memory to allocate (see also --" OPT_SOCKET_MEM ")\n"
lib/librte_eal/common/eal_options.h +2 -0
@@ -77,6 +77,8 @@ enum {OPT_CREATE_UIO_DEV_NUM , #define OPT_VFIO_INTR "vfio-intr"OPT_VFIO_INTR_NUM , +#define OPT_LCORES "lcores" +OPT_LCORES_NUM , OPT_LONG_MAX_NUM };
lib/librte_eal/linuxapp/eal/Makefile +1 -0
@@ -99,6 +99,7 @@ CFLAGS_eal_hugepage_info.o := -D_GNU_SOURCE CFLAGS_eal_pci.o := -D_GNU_SOURCE CFLAGS_eal_pci_vfio.o := -D_GNU_SOURCE CFLAGS_eal_common_whitelist.o := -D_GNU_SOURCE +CFLAGS_eal_common_options.o := -D_GNU_SOURCE # workaround for a gcc bug with noreturn attribute # http://gcc.gnu.org/bugzilla/show_bug.cgi?id=12603
Signature · 1 line
1.8.1.4
PATCH v6 4/19 eal: fix wrong strnlen() return value in 32bit icc
In reply to a message not in the archiveThe problem is that strnlen() here may return invalid value with 32bit icc. (actually it returns it’s second parameter,e.g: sysconf(_SC_ARG_MAX)).
It starts to manifest hwen max_len parameter is > 2M and using icc –m32 –O2 (or above).
---
v5 changes:
using strlen instead of strnlen.
lib/librte_eal/common/eal_common_options.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
lib/librte_eal/common/eal_common_options.c +3 -3
@@ -167,7 +167,7 @@ eal_parse_coremask(const char *coremask)if (coremask[0 ] =='0' && ((coremask[1 ] =='x' ) || (coremask[1 ] =='X' ))) coremask +=2 ; - i =strnlen (coremask,PATH_MAX ); + i =strlen (coremask);while ((i >0 ) &&isblank (coremask[i -1 ])) i--;if (i ==0 )
@@ -227,7 +227,7 @@ eal_parse_corelist(const char *corelist)/* Remove all blank characters ahead and after */ while (isblank (*corelist)) corelist++; - i =strnlen (corelist,sysconf (_SC_ARG_MAX)); + i =strlen (corelist);while ((i >0 ) &&isblank (corelist[i -1 ])) i--;
@@ -472,7 +472,7 @@ eal_parse_lcores(const char *lcores)/* Remove all blank characters ahead and after */ while (isblank (*lcores)) lcores++; - i =strnlen (lcores,sysconf (_SC_ARG_MAX)); + i =strlen (lcores);while ((i >0 ) &&isblank (lcores[i -1 ])) i--;
Signature · 1 line
1.8.1.4
A message that is not in the archive (sent off-list or not yet received): 1423791501-1555-5-git-send-email-cunming.liang-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org
Re: [PATCH v6 04/19] eal: fix wrong strnlen() return value in 32bit icc
Quoted 18 lines · Cunming Liang
The problem is that
strnlen()here may return invalid value with 32bit icc. (actually it returns it’s second parameter,e.g:sysconf(_SC_ARG_MAX)).
It starts to manifest hwenmax_lenparameter is > 2M and using icc –m32 –O2 (or above).Suggested-by Konstantin Ananyev <[email protected]>Signed-off-by Cunming Liang <[email protected]>---
v5 changes:
using strlen instead of strnlen.lib/librte_eal/common/eal_common_options.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)lib/librte_eal/common/eal_common_options.c +0
-0
lib/librte_eal/common/eal_common_options.c eal_parse_coremask(const char *coremask) · line 170
Quoted 5 lines
lib/librte_eal/common/eal_common_options.c +1
-1@@ -167,7 +167,7 @@ eal_parse_coremask(const char *coremask)if (coremask[0 ] =='0' && ((coremask[1 ] =='x' ) || (coremask[1 ] =='X' ))) coremask +=2 ; - i =strnlen (coremask,PATH_MAX ); + i =strlen (coremask);
This is crash prone. If coremask is passed in without a trailing null pointer, strlen will return a huge value that can overrun the array.
This seems like a bug in icc, and should be fixed there.
Neil
A message that is not in the archive (sent off-list or not yet received): 20150213134933.GA13495-0o1r3XBGOEbbgkc5XkKeNuvMHUBZFtU3YPYVAmT7z5s@public.gmane.org
Re: [PATCH v6 04/19] eal: fix wrong strnlen() return value in 32bit icc
Hi Neil,
Quoted 14 lines · Neil Horman
Quoted 13 lines · Cunming Liang
The problem is that
strnlen()here may return invalid value with 32bit icc. (actually it returns it’s second parameter,e.g:sysconf(_SC_ARG_MAX)).
It starts to manifest hwenmax_lenparameter is > 2M and using icc –m32 –O2 (or above).Suggested-by Konstantin Ananyev <[email protected]>Signed-off-by Cunming Liang <[email protected]>---
v5 changes:
using strlen instead of strnlen.lib/librte_eal/common/eal_common_options.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
Quoted 12 lines
lib/librte_eal/common/eal_common_options.c eal_parse_coremask(const char *coremask) · line 170
Quoted 10 lines
lib/librte_eal/common/eal_common_options.c +1
-1@@ -167,7 +167,7 @@ eal_parse_coremask(const char *coremask)if (coremask[0 ] =='0' && ((coremask[1 ] =='x' ) || (coremask[1 ] =='X' ))) coremask +=2 ; - i =strnlen (coremask,PATH_MAX ); + i =strlen (coremask);This is crash prone. If coremask is passed in without a trailing null pointer, strlen will return a huge value that can overrun the array.
We discussed that in a previous thread:
http://dpdk.org/ml/archives/dev/2015-February/012552.html
coremask is always a valid nul-terminated string as it comes from argv[] table.
It is not a memory fragment that is controlled by a user, so I don't think using strnlen() instead of strlen() would solve any issue.
Regards,
Olivier
A message that is not in the archive (sent off-list or not yet received): [email protected]
Re: [PATCH v6 04/19] eal: fix wrong strnlen() return value in 32bit icc
Quoted 30 lines · Olivier MATZ
Hi Neil,
Quoted 14 lines · Neil Horman
Quoted 13 lines · Cunming Liang
The problem is that
strnlen()here may return invalid value with 32bit icc. (actually it returns it’s second parameter,e.g:sysconf(_SC_ARG_MAX)).
It starts to manifest hwenmax_lenparameter is > 2M and using icc –m32 –O2 (or above).Suggested-by Konstantin Ananyev <[email protected]>Signed-off-by Cunming Liang <[email protected]>---
v5 changes:
using strlen instead of strnlen.lib/librte_eal/common/eal_common_options.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)Quoted 12 lines
lib/librte_eal/common/eal_common_options.c eal_parse_coremask(const char *coremask) · line 170
Quoted 10 lines
lib/librte_eal/common/eal_common_options.c +1
-1@@ -167,7 +167,7 @@ eal_parse_coremask(const char *coremask)if (coremask[0 ] =='0' && ((coremask[1 ] =='x' ) || (coremask[1 ] =='X' ))) coremask +=2 ; - i =strnlen (coremask,PATH_MAX ); + i =strlen (coremask);This is crash prone. If coremask is passed in without a trailing null pointer, strlen will return a huge value that can overrun the array.
Quoted 8 lines
We discussed that in a previous thread:
http://dpdk.org/ml/archives/dev/2015-February/012552.htmlcoremask is always a valid nul-terminated string as it comes from argv[] table.
It is not a memory fragment that is controlled by a user, so I don't think usingstrnlen()instead ofstrlen()would solve any issue.
Thats absolutely false, you can't in any way make that assertion. eal_parse_common_option is a public API call. An application can construct its own string to pass into the parser. The test applications all use the command line functions so its not a visible issue from the test apps, but you can't assume what the test apps do is what everyone will do. It would be one thing if you could make the parse_common_option function private, but with the current layout you can't so you have to be ready for garbage input.
Neil
Quoted 3 lines
Regards,
Olivier
A message that is not in the archive (sent off-list or not yet received): 20150213175523.GA17402-0o1r3XBGOEbbgkc5XkKeNuvMHUBZFtU3YPYVAmT7z5s@public.gmane.org
Re: [PATCH v6 04/19] eal: fix wrong strnlen() return value in 32bit icc
Quoted 43 lines
-----Original Message-----
From: dev [mailto:[email protected]] On Behalf Of Neil Horman
Sent: Friday, February 13, 2015 5:55 PM
To: Olivier MATZ
Cc: [email protected]
Subject: Re: [dpdk-dev] [PATCH v6 04/19] eal: fix wrongstrnlen()return value in 32bit iccQuoted 33 lines · Olivier MATZ
Hi Neil,
Quoted 14 lines · Neil Horman
Quoted 13 lines · Cunming Liang
The problem is that
strnlen()here may return invalid value with 32bit icc. (actually it returns it’s second parameter,e.g:sysconf(_SC_ARG_MAX)).
It starts to manifest hwenmax_lenparameter is > 2M and using icc –m32 –O2 (or above).Suggested-by Konstantin Ananyev <[email protected]>Signed-off-by Cunming Liang <[email protected]>---
v5 changes:
using strlen instead of strnlen.lib/librte_eal/common/eal_common_options.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)Quoted 12 lines
lib/librte_eal/common/eal_common_options.c eal_parse_coremask(const char *coremask) · line 170
Quoted 10 lines
lib/librte_eal/common/eal_common_options.c +1
-1@@ -167,7 +167,7 @@ eal_parse_coremask(const char *coremask)if (coremask[0 ] =='0' && ((coremask[1 ] =='x' ) || (coremask[1 ] =='X' ))) coremask +=2 ; - i =strnlen (coremask,PATH_MAX ); + i =strlen (coremask);This is crash prone. If coremask is passed in without a trailing null pointer, strlen will return a huge value that can overrun the array.
We discussed that in a previous thread:
http://dpdk.org/ml/archives/dev/2015-February/012552.html
Quoted 7 lines
Quoted 5 lines
coremask is always a valid nul-terminated string as it comes from argv[] table.
It is not a memory fragment that is controlled by a user, so I don't think usingstrnlen()instead ofstrlen()would solve any issue.Thats absolutely false, you can't in any way make that assertion.
eal_parse_common_optionis a public API call.
Why do you consider is as public API?
It is declared in private librte_eal header file:lib/librte_eal/common/eal_options.h
So yes, in theory it can be used by some other functions inside librte_eal. But it shouldn't be visible outside librte_eal.
Konstantin
Quoted 12 lines
An application can construct its
own string to pass into the parser. The test applications all use the command line functions so its not a visible issue from the test apps, but you can't assume what the test apps do is what everyone will do. It would be one thing if you could make theparse_common_optionfunction private, but with the current layout you can't so you have to be ready for garbage input.Neil
Quoted 3 lines
Regards,
Olivier
A message that is not in the archive (sent off-list or not yet received): 2601191342CEEE43887BDE71AB977258213E64ED-pww93C2UFcwu0RiL9chJVbfspsVTdybXVpNB7YpNyf8@public.gmane.org
Neil Horman
Acked-byRe: [PATCH v6 04/19] eal: fix wrong strnlen() return value in 32bit icc
Quoted 51 lines · Konstantin
Quoted 43 lines
-----Original Message-----
From: dev [mailto:[email protected]] On Behalf Of Neil Horman
Sent: Friday, February 13, 2015 5:55 PM
To: Olivier MATZ
Cc: [email protected]
Subject: Re: [dpdk-dev] [PATCH v6 04/19] eal: fix wrongstrnlen()return value in 32bit iccQuoted 33 lines · Olivier MATZ
Hi Neil,
Quoted 14 lines · Neil Horman
Quoted 13 lines · Cunming Liang
The problem is that
strnlen()here may return invalid value with 32bit icc. (actually it returns it’s second parameter,e.g:sysconf(_SC_ARG_MAX)).
It starts to manifest hwenmax_lenparameter is > 2M and using icc –m32 –O2 (or above).Suggested-by Konstantin Ananyev <[email protected]>Signed-off-by Cunming Liang <[email protected]>---
v5 changes:
using strlen instead of strnlen.lib/librte_eal/common/eal_common_options.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)Quoted 12 lines
lib/librte_eal/common/eal_common_options.c eal_parse_coremask(const char *coremask) · line 170
Quoted 10 lines
lib/librte_eal/common/eal_common_options.c +1
-1@@ -167,7 +167,7 @@ eal_parse_coremask(const char *coremask)if (coremask[0 ] =='0' && ((coremask[1 ] =='x' ) || (coremask[1 ] =='X' ))) coremask +=2 ; - i =strnlen (coremask,PATH_MAX ); + i =strlen (coremask);This is crash prone. If coremask is passed in without a trailing null pointer, strlen will return a huge value that can overrun the array.
We discussed that in a previous thread:
http://dpdk.org/ml/archives/dev/2015-February/012552.htmlQuoted 7 lines
Quoted 5 lines
coremask is always a valid nul-terminated string as it comes from argv[] table.
It is not a memory fragment that is controlled by a user, so I don't think usingstrnlen()instead ofstrlen()would solve any issue.Thats absolutely false, you can't in any way make that assertion.
eal_parse_common_optionis a public API call.
Quoted 7 lines
Why do you consider is as public API?
It is declared in privatelibrte_ealheader file:lib/librte_eal/common/eal_options.h
So yes, in theory it can be used by some other functions insidelibrte_eal. But it shouldn't be visible outsidelibrte_eal.
Konstantin
I apologize, I misread the Makefile. I thought I saw that it was symlinked as a publically accessible header file, but thats not the case. As such, it should be ok.
Quoted 12 lines
Quoted 12 lines
An application can construct its
own string to pass into the parser. The test applications all use the command line functions so its not a visible issue from the test apps, but you can't assume what the test apps do is what everyone will do. It would be one thing if you could make theparse_common_optionfunction private, but with the current layout you can't so you have to be ready for garbage input.Neil
Quoted 3 lines
Regards,
Olivier
Re: [PATCH v6 04/19] eal: fix wrong strnlen() return value in 32bit icc
In reply to a message not in the archiveQuoted 60 lines
-----Original Message-----
From: Neil Horman [mailto:[email protected]]
Sent: Saturday, February 14, 2015 1:55 AM
To: Olivier MATZ
Cc: Liang, Cunming; [email protected]
Subject: Re: [dpdk-dev] [PATCH v6 04/19] eal: fix wrongstrnlen()return value in 32bit iccQuoted 7 lines · Olivier MATZ
Hi Neil,
Quoted 4 lines · Neil Horman
Quoted 3 lines · Cunming Liang
The problem is that
strnlen()here may return invalid value with 32bit icc. (actually it returns it’s second parameter,e.g:sysconf(_SC_ARG_MAX)). It starts to manifest hwenmax_lenparameter is > 2M and using icc –m32 –O2 (or above).
Quoted 11 lines
Quoted 11 lines
Review
Quoted 11 lines
Suggested-by Konstantin Ananyev <[email protected]>Signed-off-by Cunming Liang <[email protected]>---
v5 changes:
using strlen instead of strnlen.lib/librte_eal/common/eal_common_options.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)(quoted diff) +0
-0
b/lib/librte_eal/common/eal_common_options.cQuoted 12 lines
Quoted 11 lines
lib/librte_eal/common/eal_common_options.c eal_parse_coremask(const char *coremask) · line 170
Quoted 9 lines
index 178e303..9cf2faa 100644
lib/librte_eal/common/eal_common_options.c +1
-1@@ -167,7 +167,7 @@ eal_parse_coremask(const char *coremask)if (coremask[0 ] =='0' && ((coremask[1 ] =='x' ) || (coremask[1 ] =='X' ))) coremask +=2 ; - i =strnlen (coremask,PATH_MAX ); + i =strlen (coremask);This is crash prone. If coremask is passed in without a trailing null pointer, strlen will return a huge value that can overrun the array.
Quoted 8 lines
We discussed that in a previous thread:
http://dpdk.org/ml/archives/dev/2015-February/012552.htmlcoremask is always a valid nul-terminated string as it comes from argv[] table.
It is not a memory fragment that is controlled by a user, so I don't think usingstrnlen()instead ofstrlen()would solve any issue.Thats absolutely false, you can't in any way make that assertion.
eal_parse_common_optionis a public API call. An application can construct its own string to pass into the parser. The test applications all use the command line functions so its not a visible issue from the test apps, but you can't assume what the test apps do is what everyone will do. It would be one thing if you could make theparse_common_optionfunction private, but with the current
layout you can't so you have to be ready for garbage input.
Quoted 1 line
Neil
[LCM] It sounds reasonable to me. I'll rollback the code and use strnlen(coremask, ARG_MAX) instead.
Quoted 4 lines
Quoted 4 lines
Regards,
Olivier
A message that is not in the archive (sent off-list or not yet received): D0158A423229094DA7ABF71CF2FA0DA3118DA511-E2R4CRU6q/[email protected]
Re: [PATCH v6 04/19] eal: fix wrong strnlen() return value in 32bit icc
Hi,
Quoted 28 lines · Cunming
Quoted 28 lines
Quoted 11 lines
Quoted 10 lines
lib/librte_eal/common/eal_common_options.c eal_parse_coremask(const char *coremask) · line 170
Quoted 8 lines
lib/librte_eal/common/eal_common_options.c +1
-1@@ -167,7 +167,7 @@ eal_parse_coremask(const char *coremask)if (coremask[0 ] =='0' && ((coremask[1 ] =='x' ) || (coremask[1 ] =='X' ))) coremask +=2 ; - i =strnlen (coremask,PATH_MAX ); + i =strlen (coremask);This is crash prone. If coremask is passed in without a trailing null pointer, strlen will return a huge value that can overrun the array.
Quoted 8 lines
We discussed that in a previous thread:
http://dpdk.org/ml/archives/dev/2015-February/012552.htmlcoremask is always a valid nul-terminated string as it comes from argv[] table.
It is not a memory fragment that is controlled by a user, so I don't think usingstrnlen()instead ofstrlen()would solve any issue.Thats absolutely false, you can't in any way make that assertion.
eal_parse_common_optionis a public API call. An application can construct its own string to pass into the parser. The test applications all use the command line functions so its not a visible issue from the test apps, but you can't assume what the test apps do is what everyone will do. It would be one thing if you could make theparse_common_optionfunction private, but with the current
layout you can't so you have to be ready for garbage input.
Quoted 2 lines
Quoted 1 line
Neil
[LCM] It sounds reasonable to me. I'll rollback the code and use
strnlen(coremask, ARG_MAX)instead.
I still don't agree that we should use strnlen(coremask, ARG_MAX).
The API of eal_parse_coremask() requires that a valid string is passed as an argument, so strlen() is perfectly fine. It's up to the caller to ensure that the string is valid.
Using strnlen(coremask, ARG_MAX) in eal_parse_coremask() with an arbitrary length does not protect from having a segfault in case the string is invalid and the caller's buffer length is < ARG_MAX.
This would still be true even if eal_parse_coremask() is public.
Regards,
Olivier
PATCH v6 5/19 eal: add support parsing socket_id from cpuset
In reply to a message not in the archiveIt returns the socket_id if all cpus in the cpuset belongs to the same NUMA node, otherwise it will return SOCKET_ID_ANY.
---
v5 changes:
expose cpu_socket_id as eal_cpu_socket_id for linuxapp eal_cpuset_socket_id() remove static inline and move to c file
lib/librte_eal/bsdapp/eal/eal_lcore.c | 7 +++++++ lib/librte_eal/common/eal_thread.h | 11 +++++++++++ lib/librte_eal/linuxapp/eal/eal_lcore.c | 7 ++++--- 3 files changed, 22 insertions(+), 3 deletions(-)
lib/librte_eal/bsdapp/eal/eal_lcore.c +7 -0
@@ -41,6 +41,7 @@#include <rte_debug.h> #include "eal_private.h" +#include "eal_thread.h" /* No topology information available on FreeBSD including NUMA info */ #define cpu_core_id (X ) 0
@@ -112,3 +113,9 @@ rte_eal_cpu_init(void)return 0 ; } + +unsigned +eal_cpu_socket_id (__rte_unused unsigned cpu_id) +{ +return cpu_socket_id (cpu_id); +}
lib/librte_eal/common/eal_thread.h +11 -0
@@ -50,4 +50,15 @@ __attribute__((noreturn)) void *eal_thread_loop(void *arg);*/ void eal_thread_init_master (unsigned lcore_id); +/** +* Get the NUMA socket id from cpu id. +* This function is private to EAL. +* +* @param cpu_id +* The logical process id. +* @return +* socket_id or SOCKET_ID_ANY +*/ +unsigned eal_cpu_socket_id (unsigned cpu_id); +#endif /* EAL_THREAD_H */
lib/librte_eal/linuxapp/eal/eal_lcore.c +4 -3
@@ -45,6 +45,7 @@#include "eal_private.h" #include "eal_filesystem.h" +#include "eal_thread.h" #define SYS_CPU_DIR "/sys/devices/system/cpu/cpu%u"#define CORE_ID_FILE "topology/core_id"
@@ -71,8 +72,8 @@ cpu_detected(unsigned lcore_id)* Note: physical package id != NUMA node, but we use it as a * fallback for kernels which don't create a nodeY link */ -static unsigned -cpu_socket_id (unsigned lcore_id) +unsigned +eal_cpu_socket_id (unsigned lcore_id) {const char node_prefix[] ="node" ;const size_t prefix_len =sizeof (node_prefix) -1 ;
@@ -174,7 +175,7 @@ rte_eal_cpu_init(void)/* By default, each detected core is enabled */ config->lcore_role[lcore_id] =ROLE_RTE ; lcore_config[lcore_id].core_id =cpu_core_id (lcore_id); - lcore_config[lcore_id].socket_id =cpu_socket_id (lcore_id); + lcore_config[lcore_id].socket_id =eal_cpu_socket_id (lcore_id); if (lcore_config[lcore_id].socket_id >= RTE_MAX_NUMA_NODES)#ifdef RTE_EAL_ALLOW_INV_SOCKET_ID lcore_config[lcore_id].socket_id =0 ;
Signature · 1 line
1.8.1.4
A message that is not in the archive (sent off-list or not yet received): 1423791501-1555-6-git-send-email-cunming.liang-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org
Re: [PATCH v6 05/19] eal: add support parsing socket_id from cpuset
Quoted 69 lines · Cunming Liang
It returns the
socket_idif all cpus in the cpuset belongs to the same NUMA node, otherwise it will returnSOCKET_ID_ANY.Signed-off-by Cunming Liang <[email protected]>---
v5 changes:
exposecpu_socket_idaseal_cpu_socket_idfor linuxappeal_cpuset_socket_id()remove static inline and move to c filelib/librte_eal/bsdapp/eal/eal_lcore.c | 7 +++++++ lib/librte_eal/common/eal_thread.h | 11 +++++++++++ lib/librte_eal/linuxapp/eal/eal_lcore.c | 7 ++++--- 3 files changed, 22 insertions(+), 3 deletions(-)lib/librte_eal/bsdapp/eal/eal_lcore.c +7
-0@@ -41,6 +41,7 @@#include <rte_debug.h> #include "eal_private.h" +#include "eal_thread.h" /* No topology information available on FreeBSD including NUMA info */ #define cpu_core_id (X ) 0@@ -112,3 +113,9 @@ rte_eal_cpu_init(void)return 0 ; } + +unsigned +eal_cpu_socket_id (__rte_unused unsigned cpu_id) +{ +return cpu_socket_id (cpu_id); +}lib/librte_eal/common/eal_thread.h +11
-0@@ -50,4 +50,15 @@ __attribute__((noreturn)) void *eal_thread_loop(void *arg);*/ void eal_thread_init_master (unsigned lcore_id); +/** +* Get the NUMA socket id from cpu id. +* This function is private to EAL. +* +* @param cpu_id +* The logical process id. +* @return +* socket_id or SOCKET_ID_ANY +*/ +unsigned eal_cpu_socket_id (unsigned cpu_id); +#endif /* EAL_THREAD_H */ lib/librte_eal/linuxapp/eal/eal_lcore.c +1
-0@@ -45,6 +45,7 @@#include "eal_private.h" #include "eal_filesystem.h" +#include "eal_thread.h" #define SYS_CPU_DIR "/sys/devices/system/cpu/cpu%u"#define CORE_ID_FILE "topology/core_id"
lib/librte_eal/linuxapp/eal/eal_lcore.c cpu_detected(unsigned lcore_id) · line 76
Quoted 7 lines
lib/librte_eal/linuxapp/eal/eal_lcore.c +2
-2@@ -71,8 +72,8 @@ cpu_detected(unsigned lcore_id)* Note: physical package id != NUMA node, but we use it as a * fallback for kernels which don't create a nodeY link */ -static unsigned -cpu_socket_id (unsigned lcore_id) +unsigned +eal_cpu_socket_id (unsigned lcore_id)
If you want to export this symbol, then you need to add it to the version map.
Neil
A message that is not in the archive (sent off-list or not yet received): 20150213135152.GB13495-0o1r3XBGOEbbgkc5XkKeNuvMHUBZFtU3YPYVAmT7z5s@public.gmane.org
Re: [PATCH v6 05/19] eal: add support parsing socket_id from cpuset
Quoted 81 lines
-----Original Message-----
From: Neil Horman [mailto:[email protected]]
Sent: Friday, February 13, 2015 9:52 PM
To: Liang, Cunming
Cc: [email protected]
Subject: Re: [dpdk-dev] [PATCH v6 05/19] eal: add support parsingsocket_idfrom cpusetQuoted 9 lines · Cunming Liang
It returns the
socket_idif all cpus in the cpuset belongs to the same NUMA node, otherwise it will returnSOCKET_ID_ANY.Signed-off-by Cunming Liang <[email protected]>---
v5 changes:
exposecpu_socket_idaseal_cpu_socket_idfor linuxappeal_cpuset_socket_id()remove static inline and move to c fileReview
Quoted 6 lines
lib/librte_eal/bsdapp/eal/eal_lcore.c | 7 +++++++ lib/librte_eal/common/eal_thread.h | 11 +++++++++++ lib/librte_eal/linuxapp/eal/eal_lcore.c | 7 ++++--- 3 files changed, 22 insertions(+), 3 deletions(-)(quoted diff) +0
-0
b/lib/librte_eal/bsdapp/eal/eal_lcore.cReview
Quoted 22 lines
index 72f8ac2..162fb4f 100644
lib/librte_eal/bsdapp/eal/eal_lcore.c +7
-0@@ -41,6 +41,7 @@#include <rte_debug.h> #include "eal_private.h" +#include "eal_thread.h" /* No topology information available on FreeBSD including NUMA info */ #define cpu_core_id (X ) 0@@ -112,3 +113,9 @@ rte_eal_cpu_init(void)return 0 ; } + +unsigned +eal_cpu_socket_id (__rte_unused unsigned cpu_id) +{ +return cpu_socket_id (cpu_id); +}(quoted diff) +0
-0
b/lib/librte_eal/common/eal_thread.hlib/librte_eal/common/eal_thread.h __attribute__((noreturn)) void *eal_thread_loop(void
Quoted 4 lines
index b53b84d..f1ce0bd 100644
lib/librte_eal/common/eal_thread.h +0
-0@@ -50,4 +50,15 @@ __attribute__((noreturn)) void *eal_thread_loop(void*arg);
Review
Quoted 16 lines
lib/librte_eal/common/eal_thread.h +11
-0*/ void eal_thread_init_master (unsigned lcore_id); +/** +* Get the NUMA socket id from cpu id. +* This function is private to EAL. +* +* @param cpu_id +* The logical process id. +* @return +* socket_id or SOCKET_ID_ANY +*/ +unsigned eal_cpu_socket_id (unsigned cpu_id); +#endif /* EAL_THREAD_H */ (quoted diff) +0
-0
b/lib/librte_eal/linuxapp/eal/eal_lcore.cQuoted 9 lines
index 29615f8..ef8c433 100644
lib/librte_eal/linuxapp/eal/eal_lcore.c +1
-0@@ -45,6 +45,7 @@#include "eal_private.h" #include "eal_filesystem.h" +#include "eal_thread.h"
Quoted 11 lines
lib/librte_eal/linuxapp/eal/eal_lcore.c cpu_detected(unsigned lcore_id) · line 76
Quoted 10 lines
lib/librte_eal/linuxapp/eal/eal_lcore.c +2
-2#define SYS_CPU_DIR "/sys/devices/system/cpu/cpu%u"#define CORE_ID_FILE "topology/core_id"@@ -71,8 +72,8 @@ cpu_detected(unsigned lcore_id)* Note: physical package id != NUMA node, but we use it as a * fallback for kernels which don't create a nodeY link */ -static unsigned -cpu_socket_id (unsigned lcore_id) +unsigned +eal_cpu_socket_id (unsigned lcore_id)If you want to export this symbol, then you need to add it to the version map.
[LCM] They're all EAL internal function, won't plan to expose as EAL API.
Quoted 2 lines
Neil
PATCH v6 6/19 eal: new TLS definition and API declaration
In reply to a message not in the archive1. add two TLS *_socket_id* and *_cpuset*
2. add two external API rte_thread_set/get_affinity
3. add one internal API eal_thread_dump_affinity
---
v5 changes:
add comments for RTE_CPU_AFFINITY_STR_LEN
update comments for eal_thread_dump_affinity()
return void for rte_thread_get_affinity()
move rte_socket_id() change to another patch
lib/librte_eal/bsdapp/eal/eal_thread.c | 2 ++ lib/librte_eal/common/eal_thread.h | 36 +++++++++++++++++++++++++++++++ lib/librte_eal/common/include/rte_lcore.h | 26 +++++++++++++++++++++- lib/librte_eal/linuxapp/eal/eal_thread.c | 2 ++ 4 files changed, 65 insertions(+), 1 deletion(-)
lib/librte_eal/bsdapp/eal/eal_thread.c +2 -0
@@ -56,6 +56,8 @@#include "eal_thread.h" RTE_DEFINE_PER_LCORE (unsigned, _lcore_id); +RTE_DEFINE_PER_LCORE (unsigned, _socket_id); +RTE_DEFINE_PER_LCORE (rte_cpuset_t, _cpuset);/* * Send a message to a slave lcore identified by slave_id to call a
lib/librte_eal/common/eal_thread.h +36 -0
@@ -34,6 +34,8 @@#ifndef EAL_THREAD_H #define EAL_THREAD_H +#include <rte_lcore.h> +/** * basic loop of thread, called for each thread by eal_init(). *
@@ -61,4 +63,38 @@ void eal_thread_init_master(unsigned lcore_id);*/ unsigned eal_cpu_socket_id (unsigned cpu_id); +/** +* Get the NUMA socket id from cpuset. +* This function is private to EAL. +* +* @param cpusetp +* The point to a valid cpu set. +* @return +* socket_id or SOCKET_ID_ANY +*/ +int eal_cpuset_socket_id (rte_cpuset_t *cpusetp); + +/** +* Default buffer size to use with eal_thread_dump_affinity() +*/ +#define RTE_CPU_AFFINITY_STR_LEN 256 + +/** +* Dump the current pthread cpuset. +* This function is private to EAL. +* +* Note: +* If the dump size is greater than the size of given buffer, +* the string will be truncated and with '\0' at the end. +* +* @param str +* The string buffer the cpuset will dump to. +* @param size +* The string buffer size. +* @return +* 0 for success, -1 if truncation happens. +*/ +int +eal_thread_dump_affinity (char *str,unsigned size); +#endif /* EAL_THREAD_H */
lib/librte_eal/common/include/rte_lcore.h +25 -1
@@ -80,7 +80,9 @@ struct lcore_config {*/ extern struct lcore_config lcore_config[RTE_MAX_LCORE ]; -RTE_DECLARE_PER_LCORE (unsigned, _lcore_id);/**< Per core "core id". */ +RTE_DECLARE_PER_LCORE (unsigned, _lcore_id);/**< Per thread "lcore id". */ +RTE_DECLARE_PER_LCORE (unsigned, _socket_id);/**< Per thread "socket id". */ +RTE_DECLARE_PER_LCORE (rte_cpuset_t, _cpuset);/**< Per thread "cpuset". */ /** * Return the ID of the execution unit we are running on.
@@ -229,6 +231,28 @@ rte_get_next_lcore(unsigned i, int skip_master, int wrap) i<RTE_MAX_LCORE ; \ i = rte_get_next_lcore(i, 1, 0)) +/** +* Set core affinity of the current thread. +* Support both EAL and none-EAL thread and update TLS. +* +* @param cpusetp +* Point to cpu_set_t for setting current thread affinity. +* @return +* On success, return 0; otherwise return -1; +*/ +int rte_thread_set_affinity (rte_cpuset_t *cpusetp); + +/** +* Get core affinity of the current thread. +* +* @param cpusetp +* Point to cpu_set_t for getting current thread cpu affinity. +* It presumes input is not NULL, otherwise it causes panic. +* +*/ +void rte_thread_get_affinity (rte_cpuset_t *cpusetp); + + #ifdef __cplusplus }#endif
lib/librte_eal/linuxapp/eal/eal_thread.c +2 -0
@@ -56,6 +56,8 @@#include "eal_thread.h" RTE_DEFINE_PER_LCORE (unsigned, _lcore_id); +RTE_DEFINE_PER_LCORE (unsigned, _socket_id); +RTE_DEFINE_PER_LCORE (rte_cpuset_t, _cpuset);/* * Send a message to a slave lcore identified by slave_id to call a
Signature · 1 line
1.8.1.4
A message that is not in the archive (sent off-list or not yet received): 1423791501-1555-7-git-send-email-cunming.liang-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org
Re: [PATCH v6 06/19] eal: new TLS definition and API declaration
Quoted 144 lines · Cunming Liang
1. add two TLS *_socket_id* and *_cpuset*
2. add two external API rte_thread_set/get_affinity
3. add one internal APIeal_thread_dump_affinitySigned-off-by Cunming Liang <[email protected]>---
v5 changes:
add comments forRTE_CPU_AFFINITY_STR_LEN
update comments foreal_thread_dump_affinity()
return void forrte_thread_get_affinity()
moverte_socket_id()change to another patchlib/librte_eal/bsdapp/eal/eal_thread.c | 2 ++ lib/librte_eal/common/eal_thread.h | 36 +++++++++++++++++++++++++++++++ lib/librte_eal/common/include/rte_lcore.h | 26 +++++++++++++++++++++- lib/librte_eal/linuxapp/eal/eal_thread.c | 2 ++ 4 files changed, 65 insertions(+), 1 deletion(-)lib/librte_eal/bsdapp/eal/eal_thread.c +2
-0@@ -56,6 +56,8 @@#include "eal_thread.h" RTE_DEFINE_PER_LCORE (unsigned, _lcore_id); +RTE_DEFINE_PER_LCORE (unsigned, _socket_id); +RTE_DEFINE_PER_LCORE (rte_cpuset_t, _cpuset);/* * Send a message to a slave lcore identified by slave_id to call a lib/librte_eal/common/eal_thread.h +36
-0@@ -34,6 +34,8 @@#ifndef EAL_THREAD_H #define EAL_THREAD_H +#include <rte_lcore.h> +/** * basic loop of thread, called for each thread by eal_init(). * @@ -61,4 +63,38 @@ void eal_thread_init_master(unsigned lcore_id);*/ unsigned eal_cpu_socket_id (unsigned cpu_id); +/** +* Get the NUMA socket id from cpuset. +* This function is private to EAL. +* +* @param cpusetp +* The point to a valid cpu set. +* @return +* socket_id or SOCKET_ID_ANY +*/ +int eal_cpuset_socket_id (rte_cpuset_t *cpusetp); + +/** +* Default buffer size to use with eal_thread_dump_affinity() +*/ +#define RTE_CPU_AFFINITY_STR_LEN 256 + +/** +* Dump the current pthread cpuset. +* This function is private to EAL. +* +* Note: +* If the dump size is greater than the size of given buffer, +* the string will be truncated and with '\0' at the end. +* +* @param str +* The string buffer the cpuset will dump to. +* @param size +* The string buffer size. +* @return +* 0 for success, -1 if truncation happens. +*/ +int +eal_thread_dump_affinity (char *str,unsigned size); +#endif /* EAL_THREAD_H */ lib/librte_eal/common/include/rte_lcore.h +25
-1@@ -80,7 +80,9 @@ struct lcore_config {*/ extern struct lcore_config lcore_config[RTE_MAX_LCORE ]; -RTE_DECLARE_PER_LCORE (unsigned, _lcore_id);/**< Per core "core id". */ +RTE_DECLARE_PER_LCORE (unsigned, _lcore_id);/**< Per thread "lcore id". */ +RTE_DECLARE_PER_LCORE (unsigned, _socket_id);/**< Per thread "socket id". */ +RTE_DECLARE_PER_LCORE (rte_cpuset_t, _cpuset);/**< Per thread "cpuset". */ /** * Return the ID of the execution unit we are running on. @@ -229,6 +231,28 @@ rte_get_next_lcore(unsigned i, int skip_master, int wrap) i<RTE_MAX_LCORE ; \ i = rte_get_next_lcore(i, 1, 0)) +/** +* Set core affinity of the current thread. +* Support both EAL and none-EAL thread and update TLS. +* +* @param cpusetp +* Point to cpu_set_t for setting current thread affinity. +* @return +* On success, return 0; otherwise return -1; +*/ +int rte_thread_set_affinity (rte_cpuset_t *cpusetp); + +/** +* Get core affinity of the current thread. +* +* @param cpusetp +* Point to cpu_set_t for getting current thread cpu affinity. +* It presumes input is not NULL, otherwise it causes panic. +* +*/ +void rte_thread_get_affinity (rte_cpuset_t *cpusetp); + + #ifdef __cplusplus }#endif lib/librte_eal/linuxapp/eal/eal_thread.c +2
-0@@ -56,6 +56,8 @@#include "eal_thread.h" RTE_DEFINE_PER_LCORE (unsigned, _lcore_id); +RTE_DEFINE_PER_LCORE (unsigned, _socket_id); +RTE_DEFINE_PER_LCORE (rte_cpuset_t, _cpuset);/* * Send a message to a slave lcore identified by slave_id to call a Signature · 1 line
1.8.1.4
All of these exported functions need to be exported in the version map. Also, I don't think its a good idea to simply expose the per lcore cpuset variables. It would be far better to create an api around them
Neil
A message that is not in the archive (sent off-list or not yet received): 20150213135807.GC13495-0o1r3XBGOEbbgkc5XkKeNuvMHUBZFtU3YPYVAmT7z5s@public.gmane.org
Re: [PATCH v6 06/19] eal: new TLS definition and API declaration
Hi,
Quoted 156 lines
-----Original Message-----
From: Neil Horman [mailto:[email protected]]
Sent: Friday, February 13, 2015 9:58 PM
To: Liang, Cunming
Cc: [email protected]
Subject: Re: [dpdk-dev] [PATCH v6 06/19] eal: new TLS definition and API declarationQuoted 12 lines · Cunming Liang
1. add two TLS *_socket_id* and *_cpuset*
2. add two external API rte_thread_set/get_affinity
3. add one internal APIeal_thread_dump_affinitySigned-off-by Cunming Liang <[email protected]>---
v5 changes:
add comments forRTE_CPU_AFFINITY_STR_LEN
update comments foreal_thread_dump_affinity()
return void forrte_thread_get_affinity()
moverte_socket_id()change to another patchQuoted 2 lines
lib/librte_eal/bsdapp/eal/eal_thread.c | 2 ++ lib/librte_eal/common/eal_thread.h | 36+++++++++++++++++++++++++++++++
Review
Quoted 5 lines
lib/librte_eal/common/include/rte_lcore.h | 26 +++++++++++++++++++++- lib/librte_eal/linuxapp/eal/eal_thread.c | 2 ++ 4 files changed, 65 insertions(+), 1 deletion(-)(quoted diff) +0
-0
b/lib/librte_eal/bsdapp/eal/eal_thread.cReview
Quoted 13 lines
index ab05368..10220c7 100644
lib/librte_eal/bsdapp/eal/eal_thread.c +2
-0@@ -56,6 +56,8 @@#include "eal_thread.h" RTE_DEFINE_PER_LCORE (unsigned, _lcore_id); +RTE_DEFINE_PER_LCORE (unsigned, _socket_id); +RTE_DEFINE_PER_LCORE (rte_cpuset_t, _cpuset);/* * Send a message to a slave lcore identified by slave_id to call a (quoted diff) +0
-0
b/lib/librte_eal/common/eal_thread.hReview
Quoted 52 lines
index f1ce0bd..e4e76b9 100644
lib/librte_eal/common/eal_thread.h +36
-0@@ -34,6 +34,8 @@#ifndef EAL_THREAD_H #define EAL_THREAD_H +#include <rte_lcore.h> +/** * basic loop of thread, called for each thread by eal_init(). * @@ -61,4 +63,38 @@ void eal_thread_init_master(unsigned lcore_id);*/ unsigned eal_cpu_socket_id (unsigned cpu_id); +/** +* Get the NUMA socket id from cpuset. +* This function is private to EAL. +* +* @param cpusetp +* The point to a valid cpu set. +* @return +* socket_id or SOCKET_ID_ANY +*/ +int eal_cpuset_socket_id (rte_cpuset_t *cpusetp); + +/** +* Default buffer size to use with eal_thread_dump_affinity() +*/ +#define RTE_CPU_AFFINITY_STR_LEN 256 + +/** +* Dump the current pthread cpuset. +* This function is private to EAL. +* +* Note: +* If the dump size is greater than the size of given buffer, +* the string will be truncated and with '\0' at the end. +* +* @param str +* The string buffer the cpuset will dump to. +* @param size +* The string buffer size. +* @return +* 0 for success, -1 if truncation happens. +*/ +int +eal_thread_dump_affinity (char *str,unsigned size); +#endif /* EAL_THREAD_H */ (quoted diff) +0
-0
b/lib/librte_eal/common/include/rte_lcore.hlib/librte_eal/common/include/rte_lcore.h struct lcore_config { · line 83
Quoted 9 lines
index 4c7d6bb..33f558e 100644
lib/librte_eal/common/include/rte_lcore.h +1
-1@@ -80,7 +80,9 @@ struct lcore_config {*/ extern struct lcore_config lcore_config[RTE_MAX_LCORE ]; -RTE_DECLARE_PER_LCORE (unsigned, _lcore_id);/**< Per core "core id". */ +RTE_DECLARE_PER_LCORE (unsigned, _lcore_id);/**< Per thread "lcore id". */
lib/librte_eal/common/include/rte_lcore.h struct lcore_config { · line 84
Quoted 1 line
lib/librte_eal/common/include/rte_lcore.h +1
-0+RTE_DECLARE_PER_LCORE (unsigned, _socket_id);/**< Per thread "socket id". */
lib/librte_eal/common/include/rte_lcore.h struct lcore_config { · line 85
Quoted 1 line
lib/librte_eal/common/include/rte_lcore.h +1
-0+RTE_DECLARE_PER_LCORE (rte_cpuset_t, _cpuset);/**< Per thread "cpuset". */
lib/librte_eal/common/include/rte_lcore.h rte_get_next_lcore(unsigned i, int skip_master, int
Quoted 4 lines
lib/librte_eal/common/include/rte_lcore.h +0
-0/** * Return the ID of the execution unit we are running on. @@ -229,6 +231,28 @@ rte_get_next_lcore(unsigned i, int skip_master, intwrap)
Review
Quoted 29 lines
lib/librte_eal/common/include/rte_lcore.h +22
-0i<RTE_MAX_LCORE ; \ i = rte_get_next_lcore(i, 1, 0)) +/** +* Set core affinity of the current thread. +* Support both EAL and none-EAL thread and update TLS. +* +* @param cpusetp +* Point to cpu_set_t for setting current thread affinity. +* @return +* On success, return 0; otherwise return -1; +*/ +int rte_thread_set_affinity (rte_cpuset_t *cpusetp); + +/** +* Get core affinity of the current thread. +* +* @param cpusetp +* Point to cpu_set_t for getting current thread cpu affinity. +* It presumes input is not NULL, otherwise it causes panic. +* +*/ +void rte_thread_get_affinity (rte_cpuset_t *cpusetp); + + #ifdef __cplusplus }#endif (quoted diff) +0
-0
b/lib/librte_eal/linuxapp/eal/eal_thread.cQuoted 10 lines
index 80a985f..748a83a 100644
lib/librte_eal/linuxapp/eal/eal_thread.c +2
-0@@ -56,6 +56,8 @@#include "eal_thread.h" RTE_DEFINE_PER_LCORE (unsigned, _lcore_id); +RTE_DEFINE_PER_LCORE (unsigned, _socket_id); +RTE_DEFINE_PER_LCORE (rte_cpuset_t, _cpuset);
Quoted 9 lines
Quoted 6 lines
lib/librte_eal/linuxapp/eal/eal_thread.c +0
-1/* * Send a message to a slave lcore identified by slave_id to call a -- 1.8.1.4
All of these exported functions need to be exported in the version map. Also, I don't think its a good idea to simply expose the per lcore cpuset variables. It would be far better to create an api around them
[LCM] Thanks for the remind, I haven't taken care of the version map.
The rte_thread_set/get_affinity() are the api around _cpuset, so do you suggest we don't put 'per_lcore__cpuset' into rte_eal_version.map ? On this point, I agree with you and think we'd better not expose 'per_lcore__socket_id' as well, what do you think ?
Quoted 2 lines
Neil
A message that is not in the archive (sent off-list or not yet received): D0158A423229094DA7ABF71CF2FA0DA3118DA4D0-E2R4CRU6q/[email protected]
Re: [PATCH v6 06/19] eal: new TLS definition and API declaration
Quoted 167 lines · Cunming
Hi,
Quoted 156 lines
-----Original Message-----
From: Neil Horman [mailto:[email protected]]
Sent: Friday, February 13, 2015 9:58 PM
To: Liang, Cunming
Cc: [email protected]
Subject: Re: [dpdk-dev] [PATCH v6 06/19] eal: new TLS definition and API declarationQuoted 12 lines · Cunming Liang
1. add two TLS *_socket_id* and *_cpuset*
2. add two external API rte_thread_set/get_affinity
3. add one internal APIeal_thread_dump_affinitySigned-off-by Cunming Liang <[email protected]>---
v5 changes:
add comments forRTE_CPU_AFFINITY_STR_LEN
update comments foreal_thread_dump_affinity()
return void forrte_thread_get_affinity()
moverte_socket_id()change to another patchQuoted 2 lines
lib/librte_eal/bsdapp/eal/eal_thread.c | 2 ++ lib/librte_eal/common/eal_thread.h | 36+++++++++++++++++++++++++++++++
Review
Quoted 5 lines
lib/librte_eal/common/include/rte_lcore.h | 26 +++++++++++++++++++++- lib/librte_eal/linuxapp/eal/eal_thread.c | 2 ++ 4 files changed, 65 insertions(+), 1 deletion(-)(quoted diff) +0
-0
b/lib/librte_eal/bsdapp/eal/eal_thread.cReview
Quoted 13 lines
index ab05368..10220c7 100644
lib/librte_eal/bsdapp/eal/eal_thread.c +2
-0@@ -56,6 +56,8 @@#include "eal_thread.h" RTE_DEFINE_PER_LCORE (unsigned, _lcore_id); +RTE_DEFINE_PER_LCORE (unsigned, _socket_id); +RTE_DEFINE_PER_LCORE (rte_cpuset_t, _cpuset);/* * Send a message to a slave lcore identified by slave_id to call a (quoted diff) +0
-0
b/lib/librte_eal/common/eal_thread.hReview
Quoted 52 lines
index f1ce0bd..e4e76b9 100644
lib/librte_eal/common/eal_thread.h +36
-0@@ -34,6 +34,8 @@#ifndef EAL_THREAD_H #define EAL_THREAD_H +#include <rte_lcore.h> +/** * basic loop of thread, called for each thread by eal_init(). * @@ -61,4 +63,38 @@ void eal_thread_init_master(unsigned lcore_id);*/ unsigned eal_cpu_socket_id (unsigned cpu_id); +/** +* Get the NUMA socket id from cpuset. +* This function is private to EAL. +* +* @param cpusetp +* The point to a valid cpu set. +* @return +* socket_id or SOCKET_ID_ANY +*/ +int eal_cpuset_socket_id (rte_cpuset_t *cpusetp); + +/** +* Default buffer size to use with eal_thread_dump_affinity() +*/ +#define RTE_CPU_AFFINITY_STR_LEN 256 + +/** +* Dump the current pthread cpuset. +* This function is private to EAL. +* +* Note: +* If the dump size is greater than the size of given buffer, +* the string will be truncated and with '\0' at the end. +* +* @param str +* The string buffer the cpuset will dump to. +* @param size +* The string buffer size. +* @return +* 0 for success, -1 if truncation happens. +*/ +int +eal_thread_dump_affinity (char *str,unsigned size); +#endif /* EAL_THREAD_H */ (quoted diff) +0
-0
b/lib/librte_eal/common/include/rte_lcore.hlib/librte_eal/common/include/rte_lcore.h struct lcore_config { · line 83
Quoted 9 lines
index 4c7d6bb..33f558e 100644
lib/librte_eal/common/include/rte_lcore.h +1
-1@@ -80,7 +80,9 @@ struct lcore_config {*/ extern struct lcore_config lcore_config[RTE_MAX_LCORE ]; -RTE_DECLARE_PER_LCORE (unsigned, _lcore_id);/**< Per core "core id". */ +RTE_DECLARE_PER_LCORE (unsigned, _lcore_id);/**< Per thread "lcore id". */
lib/librte_eal/common/include/rte_lcore.h struct lcore_config { · line 84
Quoted 1 line
lib/librte_eal/common/include/rte_lcore.h +1
-0+RTE_DECLARE_PER_LCORE (unsigned, _socket_id);/**< Per thread "socket id". */
lib/librte_eal/common/include/rte_lcore.h struct lcore_config { · line 85
Quoted 1 line
lib/librte_eal/common/include/rte_lcore.h +1
-0+RTE_DECLARE_PER_LCORE (rte_cpuset_t, _cpuset);/**< Per thread "cpuset". */
lib/librte_eal/common/include/rte_lcore.h rte_get_next_lcore(unsigned i, int skip_master, int
Quoted 4 lines
lib/librte_eal/common/include/rte_lcore.h +0
-0/** * Return the ID of the execution unit we are running on. @@ -229,6 +231,28 @@ rte_get_next_lcore(unsigned i, int skip_master, intwrap)
Review
Quoted 29 lines
lib/librte_eal/common/include/rte_lcore.h +22
-0i<RTE_MAX_LCORE ; \ i = rte_get_next_lcore(i, 1, 0)) +/** +* Set core affinity of the current thread. +* Support both EAL and none-EAL thread and update TLS. +* +* @param cpusetp +* Point to cpu_set_t for setting current thread affinity. +* @return +* On success, return 0; otherwise return -1; +*/ +int rte_thread_set_affinity (rte_cpuset_t *cpusetp); + +/** +* Get core affinity of the current thread. +* +* @param cpusetp +* Point to cpu_set_t for getting current thread cpu affinity. +* It presumes input is not NULL, otherwise it causes panic. +* +*/ +void rte_thread_get_affinity (rte_cpuset_t *cpusetp); + + #ifdef __cplusplus }#endif (quoted diff) +0
-0
b/lib/librte_eal/linuxapp/eal/eal_thread.cQuoted 10 lines
index 80a985f..748a83a 100644
lib/librte_eal/linuxapp/eal/eal_thread.c +2
-0@@ -56,6 +56,8 @@#include "eal_thread.h" RTE_DEFINE_PER_LCORE (unsigned, _lcore_id); +RTE_DEFINE_PER_LCORE (unsigned, _socket_id); +RTE_DEFINE_PER_LCORE (rte_cpuset_t, _cpuset);Quoted 9 lines
Quoted 6 lines
lib/librte_eal/linuxapp/eal/eal_thread.c +0
-1/* * Send a message to a slave lcore identified by slave_id to call a -- 1.8.1.4
All of these exported functions need to be exported in the version map. Also, I don't think its a good idea to simply expose the per lcore cpuset variables. It would be far better to create an api around them
Quoted 3 lines
[LCM] Thanks for the remind, I haven't taken care of the version map.
The rte_thread_set/get_affinity() are the api around_cpuset, so do you suggest we don't put 'per_lcore__cpuset' into rte_eal_version.map ? On this point, I agree with you and think we'd better not expose 'per_lcore__socket_id' as well, what do you think ?
Yes, absolutely, you should wrap some API around them, and make them defined symbols, only inline them if they're going to be in the hot path.
Thanks
Neil
Quoted 4 lines
Quoted 2 lines
Neil
A message that is not in the archive (sent off-list or not yet received): 20150215051700.GA4534-0o1r3XBGOEbbgkc5XkKeNuvMHUBZFtU3YPYVAmT7z5s@public.gmane.org
Re: [PATCH v6 06/19] eal: new TLS definition and API declaration
Quoted 10 lines
-----Original Message-----
From: Neil Horman [mailto:[email protected]]
Sent: Sunday, February 15, 2015 1:17 PM
To: Liang, Cunming
Cc: [email protected]
Subject: Re: [dpdk-dev] [PATCH v6 06/19] eal: new TLS definition and API declaration
[...]
Quoted 15 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
RTE_DEFINE_PER_LCORE(unsigned, _lcore_id);(quoted diff) +2
-0+RTE_DEFINE_PER_LCORE(unsigned, _socket_id); +RTE_DEFINE_PER_LCORE(rte_cpuset_t, _cpuset);Quoted 7 lines
Quoted 7 lines
Quoted 6 lines
/*
* Send a message to a slave lcore identified byslave_idto call a
--
1.8.1.4All of these exported functions need to be exported in the version map. Also,
I
Quoted 2 lines
Quoted 2 lines
don't think its a good idea to simply expose the per lcore cpuset variables. It would be far better to create an api around them
Quoted 8 lines
Quoted 2 lines
[LCM] Thanks for the remind, I haven't taken care of the version map. The rte_thread_set/get_affinity() are the api around
_cpuset, so do yousuggest we don't put '
per_lcore__cpuset' into rte_eal_version.map ?Quoted 1 line
On this point, I agree with you and think we'd better not expose
'
per_lcore__socket_id' as well, what do you think ?
Yes, absolutely, you should wrap some API around them, and make them defined
symbols, only inline them if they're going to be in the hot path.
[LCM] _socket_id is wrapped by rte_socket_id() and rte_thread_set_affinity().rte_socket_id() is defined as inline in rte_lcore.h. So finally two (rte_thread_set/get_affinity()) are added into version map. All these are updated in v7.
Quoted 8 lines
Thanks
NeilQuoted 4 lines
Quoted 2 lines
Neil
PATCH v6 7/19 eal: add eal_common_thread.c for common thread API
In reply to a message not in the archiveThe API works for both EAL thread and none EAL thread. When calling rte_thread_set_affinity, the *_socket_id* and *_cpuset* of calling thread will be updated if the thread successful set the cpu affinity.
---
v5 changes:
refine code of rte_thread_set_affinity() change rte_thread_get_affinity() return to void
lib/librte_eal/bsdapp/eal/Makefile | 1 + lib/librte_eal/common/eal_common_thread.c | 150 ++++++++++++++++++++++++++++++ lib/librte_eal/linuxapp/eal/Makefile | 2 + 3 files changed, 153 insertions(+) create mode 100644 lib/librte_eal/common/eal_common_thread.c
lib/librte_eal/bsdapp/eal/Makefile +1 -0
@@ -77,6 +77,7 @@ SRCS-$(CONFIG_RTE_LIBRTE_EAL_BSDAPP) += eal_common_hexdump.c SRCS-$(CONFIG_RTE_LIBRTE_EAL_BSDAPP) += eal_common_devargs.c SRCS-$(CONFIG_RTE_LIBRTE_EAL_BSDAPP) += eal_common_dev.c SRCS-$(CONFIG_RTE_LIBRTE_EAL_BSDAPP) += eal_common_options.c +SRCS-$(CONFIG_RTE_LIBRTE_EAL_BSDAPP) += eal_common_thread.c CFLAGS_eal.o := -D_GNU_SOURCE #CFLAGS_eal_thread.o := -D_GNU_SOURCE
lib/librte_eal/common/eal_common_thread.c new file +150 -0
150 lines not on this page · raw message
lib/librte_eal/linuxapp/eal/Makefile +2 -0
@@ -89,6 +89,7 @@ SRCS-$(CONFIG_RTE_LIBRTE_EAL_LINUXAPP) += eal_common_hexdump.c SRCS-$(CONFIG_RTE_LIBRTE_EAL_LINUXAPP) += eal_common_devargs.c SRCS-$(CONFIG_RTE_LIBRTE_EAL_LINUXAPP) += eal_common_dev.c SRCS-$(CONFIG_RTE_LIBRTE_EAL_LINUXAPP) += eal_common_options.c +SRCS-$(CONFIG_RTE_LIBRTE_EAL_LINUXAPP) += eal_common_thread.c CFLAGS_eal.o := -D_GNU_SOURCE CFLAGS_eal_lcore.o := -D_GNU_SOURCE
@@ -100,6 +101,7 @@ CFLAGS_eal_pci.o := -D_GNU_SOURCE CFLAGS_eal_pci_vfio.o := -D_GNU_SOURCE CFLAGS_eal_common_whitelist.o := -D_GNU_SOURCE CFLAGS_eal_common_options.o := -D_GNU_SOURCE +CFLAGS_eal_common_thread.o := -D_GNU_SOURCE # workaround for a gcc bug with noreturn attribute # http://gcc.gnu.org/bugzilla/show_bug.cgi?id=12603
Signature · 1 line
1.8.1.4
PATCH v6 8/19 eal: standardize init sequence between linux and bsd
In reply to a message not in the archive--- lib/librte_eal/bsdapp/eal/eal.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
lib/librte_eal/bsdapp/eal/eal.c +2 -2
@@ -509,6 +509,8 @@ rte_eal_init(int argc, char **argv)rte_eal_mcfg_complete (); +eal_thread_init_master (rte_config.master_lcore); +if (rte_eal_dev_init () <0 )rte_panic ("Cannot init pmd devices\n" );
@@ -532,8 +534,6 @@ rte_eal_init(int argc, char **argv)rte_panic ("Cannot create thread\n" ); } -eal_thread_init_master (rte_config.master_lcore); -/* * Launch a dummy function on all slave lcores, so that master lcore * knows they are all ready when this function returns.
Signature · 1 line
1.8.1.4
PATCH v6 9/19 eal: add rte_gettid() to acquire unique system tid
In reply to a message not in the archiveThe rte_gettid() wraps the linux and freebsd syscall gettid(). It provides a persistent unique thread id for the calling thread. It will save the unique id in TLS on the first time.
--- lib/librte_eal/bsdapp/eal/eal_thread.c | 9 +++++++++ lib/librte_eal/common/include/rte_eal.h | 27 +++++++++++++++++++++++++++ lib/librte_eal/linuxapp/eal/eal_thread.c | 7 +++++++ 3 files changed, 43 insertions(+)
lib/librte_eal/bsdapp/eal/eal_thread.c +9 -0
@@ -39,6 +39,7 @@#include <sched.h> #include <pthread_np.h> #include <sys/queue.h> +#include <sys/thr.h> #include <rte_debug.h> #include <rte_atomic.h>
@@ -233,3 +234,11 @@ eal_thread_loop(__attribute__((unused)) void *arg)/* pthread_exit(NULL); */ /* return NULL; */ } + +/* require calling thread tid by gettid() */ +int rte_sys_gettid (void ) +{ +long lwpid; +thr_self (&lwpid); +return (int )lwpid; +}
lib/librte_eal/common/include/rte_eal.h +27 -0
@@ -41,6 +41,9 @@*/ #include <stdint.h> +#include <sched.h> + +#include <rte_per_lcore.h> #ifdef __cplusplusextern "C" {
@@ -262,6 +265,30 @@ rte_set_application_usage_hook( rte_usage_hook_t usage_func );*/ int rte_eal_has_hugepages (void ); +/** +* A wrap API for syscall gettid. +* +* @return +* On success, returns the thread ID of calling process. +* It always successful. +*/ +int rte_sys_gettid (void ); + +/** +* Get system unique thread id. +* +* @return +* On success, returns the thread ID of calling process. +* It always successful. +*/ +static inline int rte_gettid (void ) +{ + static RTE_DEFINE_PER_LCORE(int, _thread_id) = -1; +if (RTE_PER_LCORE (_thread_id) ==-1 ) +RTE_PER_LCORE (_thread_id) =rte_sys_gettid (); +return RTE_PER_LCORE (_thread_id); +} + #ifdef __cplusplus }#endif
lib/librte_eal/linuxapp/eal/eal_thread.c +7 -0
@@ -39,6 +39,7 @@#include <pthread.h> #include <sched.h> #include <sys/queue.h> +#include <sys/syscall.h> #include <rte_debug.h> #include <rte_atomic.h>
@@ -233,3 +234,9 @@ eal_thread_loop(__attribute__((unused)) void *arg)/* pthread_exit(NULL); */ /* return NULL; */ } + +/* require calling thread tid by gettid() */ +int rte_sys_gettid (void ) +{ +return (int )syscall (SYS_gettid); +}
Signature · 1 line
1.8.1.4
PATCH v6 10/19 eal: apply affinity of EAL thread by assigned cpuset
In reply to a message not in the archiveEAL threads use assigned cpuset to set core affinity during startup. It keeps 1:1 mapping, if no '--lcores' option is used.
---
v5 changes:
add return check for dump_affinity
call rte_thread_set_affinity() directly during EAL thread set
lib/librte_eal/bsdapp/eal/eal.c | 10 +++-- lib/librte_eal/bsdapp/eal/eal_thread.c | 64 ++++++------------------------ lib/librte_eal/common/include/rte_lcore.h | 2 +- lib/librte_eal/linuxapp/eal/eal.c | 8 +++- lib/librte_eal/linuxapp/eal/eal_thread.c | 66 ++++++------------------------- 5 files changed, 37 insertions(+), 113 deletions(-)
lib/librte_eal/bsdapp/eal/eal.c +7 -3
@@ -432,6 +432,7 @@ rte_eal_init(int argc, char **argv)int i, fctret, ret;pthread_t thread_id;static rte_atomic32_t run_once =RTE_ATOMIC32_INIT (0 ); +char cpuset[RTE_CPU_AFFINITY_STR_LEN ];if (!rte_atomic32_test_and_set (&run_once))return -1 ;
@@ -502,15 +503,18 @@ rte_eal_init(int argc, char **argv)if (rte_eal_pci_init () <0 )rte_panic ("Cannot init PCI\n" ); -RTE_LOG (DEBUG ,EAL ,"Master core %u is ready (tid=%p)\n" , - rte_config.master_lcore, thread_id); -eal_check_mem_on_local_socket ();rte_eal_mcfg_complete ();eal_thread_init_master (rte_config.master_lcore); + ret =eal_thread_dump_affinity (cpuset,RTE_CPU_AFFINITY_STR_LEN ); + +RTE_LOG (DEBUG ,EAL ,"Master lcore %u is ready (tid=%p;cpuset=[%s%s])\n" , + rte_config.master_lcore, thread_id, cpuset, + ret ==0 ?"" :"..." ); +if (rte_eal_dev_init () <0 )rte_panic ("Cannot init pmd devices\n" );
lib/librte_eal/bsdapp/eal/eal_thread.c +11 -53
90 lines not on this page · raw message
lib/librte_eal/common/include/rte_lcore.h +1 -1
@@ -148,7 +148,7 @@ rte_lcore_index(int lcore_id)static inline unsigned rte_socket_id (void ) { -return lcore_config[rte_lcore_id ()].socket_id; +return RTE_PER_LCORE (_socket_id); }/**
lib/librte_eal/linuxapp/eal/eal.c +6 -2
@@ -702,6 +702,7 @@ rte_eal_init(int argc, char **argv)static rte_atomic32_t run_once =RTE_ATOMIC32_INIT (0 );struct shared_driver *solib =NULL ;const char *logid; +char cpuset[RTE_CPU_AFFINITY_STR_LEN ];if (!rte_atomic32_test_and_set (&run_once))return -1 ;
@@ -802,8 +803,11 @@ rte_eal_init(int argc, char **argv)eal_thread_init_master (rte_config.master_lcore); -RTE_LOG (DEBUG ,EAL ,"Master core %u is ready (tid=%x)\n" , - rte_config.master_lcore, (int )thread_id); + ret =eal_thread_dump_affinity (cpuset,RTE_CPU_AFFINITY_STR_LEN ); + +RTE_LOG (DEBUG ,EAL ,"Master lcore %u is ready (tid=%x;cpuset=[%s%s])\n" , + rte_config.master_lcore, (int )thread_id, cpuset, + ret ==0 ?"" :"..." );if (rte_eal_dev_init () <0 )rte_panic ("Cannot init pmd devices\n" );
lib/librte_eal/linuxapp/eal/eal_thread.c +12 -54
95 lines not on this page · raw message
Signature · 1 line
1.8.1.4
PATCH v6 11/19 enic: fix re-define freebsd compile complain
In reply to a message not in the archiveSome macro already been defined by freebsd 'sys/param.h'.
---
v5 changes:
rename the redefined MACRO instead of undefine them
lib/librte_pmd_enic/enic.h | 4 ++-- lib/librte_pmd_enic/enic_compat.h | 2 +- lib/librte_pmd_enic/vnic/vnic_dev.c | 6 +++--- 3 files changed, 6 insertions(+), 6 deletions(-)
lib/librte_pmd_enic/enic.h +2 -2
@@ -66,9 +66,9 @@#define ENIC_CALC_IP_CKSUM 1#define ENIC_CALC_TCP_UDP_CKSUM 2#define ENIC_MAX_MTU 9000 -#define PAGE_SIZE 4096 +#define ENIC_PAGE_SIZE 4096#define PAGE_ROUND_UP (x) \ - ((((unsigned long)(x)) + PAGE_SIZE-1) & (~(PAGE_SIZE-1))) + ((((unsigned long)(x)) + ENIC_PAGE_SIZE-1) & (~(ENIC_PAGE_SIZE-1)))#define ENICPMD_VFIO_PATH "/dev/vfio/vfio"/*#define ENIC_DESC_COUNT_MAKE_ODD (x) do{if ((~(x)) & 1) { (x)--; } }while(0)*/
lib/librte_pmd_enic/enic_compat.h +1 -1
@@ -67,7 +67,7 @@ #define pr_warn(y, args...) dev_warning(0, y, ##args)#define BUG () pr_err("BUG at %s:%d", __func__, __LINE__) -#define ALIGN (x, a) __ALIGN_MASK(x, (typeof(x))(a)-1) +#define VNIC_ALIGN (x, a) __ALIGN_MASK(x, (typeof(x))(a)-1)#define __ALIGN_MASK (x, mask) (((x)+(mask))&~(mask))#define udelay usleep#define DIV_ROUND_UP (n, d) (((n) + (d) - 1) / (d))
lib/librte_pmd_enic/vnic/vnic_dev.c +3 -3
@@ -242,9 +242,9 @@ unsigned int vnic_dev_desc_ring_size(struct vnic_dev_ring *ring,if (desc_count ==0 ) desc_count =4096 ; - ring->desc_count =ALIGN (desc_count, count_align); + ring->desc_count =VNIC_ALIGN (desc_count, count_align); - ring->desc_size =ALIGN (desc_size, desc_align); + ring->desc_size =VNIC_ALIGN (desc_size, desc_align); ring->size = ring->desc_count * ring->desc_size; ring->size_unaligned = ring->size + ring->base_align;
@@ -294,7 +294,7 @@ int vnic_dev_alloc_desc_ring(__attribute__((unused)) struct vnic_dev *vdev, ring->base_addr_unaligned = (dma_addr_t )rz->phys_addr; - ring->base_addr =ALIGN (ring->base_addr_unaligned, + ring->base_addr =VNIC_ALIGN (ring->base_addr_unaligned, ring->base_align); ring->descs = (u8 *)ring->descs_unaligned + (ring->base_addr - ring->base_addr_unaligned);
Signature · 1 line
1.8.1.4
PATCH v6 12/19 malloc: fix the issue of SOCKET_ID_ANY
In reply to a message not in the archiveAdd check for rte_socket_id(), avoid get unexpected return like (-1).
--- lib/librte_malloc/malloc_heap.h | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)
lib/librte_malloc/malloc_heap.h +6 -1
@@ -44,7 +44,12 @@ extern "C" {static inline unsigned malloc_get_numa_socket (void ) { -return rte_socket_id (); +unsigned socket_id =rte_socket_id (); + +if (socket_id == (unsigned )SOCKET_ID_ANY ) +return 0 ; + +return socket_id; } void *
Signature · 1 line
1.8.1.4
A message that is not in the archive (sent off-list or not yet received): 1423791501-1555-13-git-send-email-cunming.liang-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org
Re: [PATCH v6 12/19] malloc: fix the issue of SOCKET_ID_ANY
Quoted 12 lines · Cunming Liang
Add check for
rte_socket_id(), avoid get unexpected return like (-1).Signed-off-by Cunming Liang <[email protected]>--- lib/librte_malloc/malloc_heap.h | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)lib/librte_malloc/malloc_heap.h +0
-0
lib/librte_malloc/malloc_heap.h extern "C" { · line 52
Quoted 10 lines
lib/librte_malloc/malloc_heap.h +6
-1@@ -44,7 +44,12 @@ extern "C" {static inline unsigned malloc_get_numa_socket (void ) { -return rte_socket_id (); +unsigned socket_id =rte_socket_id (); + +if (socket_id == (unsigned )SOCKET_ID_ANY ) +return 0 ; + +return socket_id;
Why is -1 unexpected? Isn't it reasonable to assume that some memory is equidistant from all cpu numa nodes?
Neil
Quoted 7 lines
lib/librte_malloc/malloc_heap.h +0
-0} void *Signature · 1 line
1.8.1.4
A message that is not in the archive (sent off-list or not yet received): 20150213175708.GB17402-0o1r3XBGOEbbgkc5XkKeNuvMHUBZFtU3YPYVAmT7z5s@public.gmane.org
Re: [PATCH v6 12/19] malloc: fix the issue of SOCKET_ID_ANY
Hi,
Quoted 24 lines
-----Original Message-----
From: Neil Horman [mailto:[email protected]]
Sent: Saturday, February 14, 2015 1:57 AM
To: Liang, Cunming
Cc: [email protected]
Subject: Re: [dpdk-dev] [PATCH v6 12/19] malloc: fix the issue ofSOCKET_ID_ANYQuoted 16 lines · Cunming Liang
Add check for
rte_socket_id(), avoid get unexpected return like (-1).Signed-off-by Cunming Liang <[email protected]>--- lib/librte_malloc/malloc_heap.h | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)lib/librte_malloc/malloc_heap.h +0
-1@@ -44,7 +44,12 @@ extern "C" {static inline unsigned malloc_get_numa_socket (void ) { -return rte_socket_id ();
Quoted 8 lines
lib/librte_malloc/malloc_heap.h extern "C" { · line 52
Quoted 6 lines
lib/librte_malloc/malloc_heap.h +6
-0+unsigned socket_id =rte_socket_id (); + +if (socket_id == (unsigned )SOCKET_ID_ANY ) +return 0 ; + +return socket_id;Why is -1 unexpected? Isn't it reasonable to assume that some memory is equidistant from all cpu numa nodes?
[LCM] One piece of memory will be whole allocated from one specific NUMA node. But won't be like some part from one and the other part from another.
If no specific NUMA node assigned(SOCKET_ID_ANY/-1), it firstly asks for the current NUMA node where current core belongs to.
'malloc_get_numa_socket()' is called on that time. When the time 1:1 thread/core mapping is assumed and the default value is 0, it always will return a none (-1) value.
Now rte_socket_id() may return -1 in the case the pthread runs on multi-cores which are not belongs to one NUMA node, or in the case _socket_id is not yet assigned and the default value is (-1). So if current _socket_id is -1, then just pick up the first node as the candidate. Probably I shall add more comments for this.
Quoted 10 lines
Neil
Quoted 7 lines
lib/librte_malloc/malloc_heap.h +0
-1} void * --1.8.1.4
A message that is not in the archive (sent off-list or not yet received): D0158A423229094DA7ABF71CF2FA0DA3118DA492-E2R4CRU6q/[email protected]
Re: [PATCH v6 12/19] malloc: fix the issue of SOCKET_ID_ANY
Quoted 34 lines · Cunming
Hi,
Quoted 24 lines
-----Original Message-----
From: Neil Horman [mailto:[email protected]]
Sent: Saturday, February 14, 2015 1:57 AM
To: Liang, Cunming
Cc: [email protected]
Subject: Re: [dpdk-dev] [PATCH v6 12/19] malloc: fix the issue ofSOCKET_ID_ANYQuoted 16 lines · Cunming Liang
Add check for
rte_socket_id(), avoid get unexpected return like (-1).Signed-off-by Cunming Liang <[email protected]>--- lib/librte_malloc/malloc_heap.h | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)lib/librte_malloc/malloc_heap.h +0
-1@@ -44,7 +44,12 @@ extern "C" {static inline unsigned malloc_get_numa_socket (void ) { -return rte_socket_id ();Quoted 8 lines
lib/librte_malloc/malloc_heap.h extern "C" { · line 52
Quoted 6 lines
lib/librte_malloc/malloc_heap.h +6
-0+unsigned socket_id =rte_socket_id (); + +if (socket_id == (unsigned )SOCKET_ID_ANY ) +return 0 ; + +return socket_id;Why is -1 unexpected? Isn't it reasonable to assume that some memory is equidistant from all cpu numa nodes?
Quoted 5 lines
[LCM] One piece of memory will be whole allocated from one specific NUMA node. But won't be like some part from one and the other part from another.
If no specific NUMA nodeassigned(SOCKET_ID_ANY/-1), it firstly asks for the current NUMA node where current core belongs to.
'malloc_get_numa_socket()' is called on that time. When the time 1:1 thread/core mapping is assumed and the default value is 0, it always will return a none (-1) value.
Nowrte_socket_id()may return -1 in the case the pthread runs on multi-cores which are not belongs to one NUMA node, or in the case_socket_idis not yet assigned and the default value is (-1). So if current_socket_idis -1, then just pick up the first node as the candidate. Probably I shall add more comments for this.Quoted 1 line
Ok, but doesn't that provide an abnormal bias for node 0? I was thinking it might be better to be honest with the application so that it can choose a node according to its own policy.
Neil
Quoted 10 lines
Quoted 9 lines
Neil
Quoted 7 lines
lib/librte_malloc/malloc_heap.h +0
-1} void * --1.8.1.4
A message that is not in the archive (sent off-list or not yet received): 20150215140917.GA6302-0o1r3XBGOEbbgkc5XkKeNuvMHUBZFtU3YPYVAmT7z5s@public.gmane.org
Re: [PATCH v6 12/19] malloc: fix the issue of SOCKET_ID_ANY
Hi,
Quoted 51 lines
-----Original Message-----
From: Neil Horman [mailto:[email protected]]
Sent: Sunday, February 15, 2015 10:09 PM
To: Liang, Cunming
Cc: [email protected]
Subject: Re: [dpdk-dev] [PATCH v6 12/19] malloc: fix the issue ofSOCKET_ID_ANYQuoted 8 lines · Cunming
Hi,
Quoted 6 lines
-----Original Message-----
From: Neil Horman [mailto:[email protected]]
Sent: Saturday, February 14, 2015 1:57 AM
To: Liang, Cunming
Cc: [email protected]
Subject: Re: [dpdk-dev] [PATCH v6 12/19] malloc: fix the issue of
SOCKET_ID_ANYQuoted 10 lines
Quoted 10 lines · Cunming Liang
Review
Quoted 8 lines
Add check for
rte_socket_id(), avoid get unexpected return like (-1).Signed-off-by Cunming Liang <[email protected]>--- lib/librte_malloc/malloc_heap.h | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)(quoted diff) +0
-0
b/lib/librte_malloc/malloc_heap.hQuoted 16 lines
Quoted 8 lines
Quoted 8 lines
index b4aec45..a47136d 100644
lib/librte_malloc/malloc_heap.h +0
-1@@ -44,7 +44,12 @@ extern "C" {static inline unsigned malloc_get_numa_socket (void ) { -return rte_socket_id ();Quoted 8 lines
lib/librte_malloc/malloc_heap.h extern "C" { · line 52
Quoted 6 lines
lib/librte_malloc/malloc_heap.h +6
-0+unsigned socket_id =rte_socket_id (); + +if (socket_id == (unsigned )SOCKET_ID_ANY ) +return 0 ; + +return socket_id;Why is -1 unexpected? Isn't it reasonable to assume that some memory is equidistant from all cpu numa nodes?
Quoted 1 line
[LCM] One piece of memory will be whole allocated from one specific NUMA
node. But won't be like some part from one and the other part from another.
Quoted 1 line
If no specific NUMA node
assigned(SOCKET_ID_ANY/-1), it firstly asks for thecurrent NUMA node where current core belongs to.
Quoted 1 line
'
malloc_get_numa_socket()' is called on that time. When the time 1:1thread/core mapping is assumed and the default value is 0, it always will return a none (-1) value.
Quoted 8 lines
Quoted 1 line
Now
rte_socket_id()may return -1 in the case the pthread runs on multi-coreswhich are not belongs to one NUMA node, or in the case
_socket_idis not yet assigned and the default value is (-1). So if current_socket_idis -1, then just pick up the first node as the candidate. Probably I shall add more comments for this.Quoted 1 line
Quoted 1 line
Ok, but doesn't that provide an abnormal bias for node 0? I was thinking it might be better to be honest with the application so that it can choose a node according to its own policy.
[LCM] Personally I like the idea grant application to make the decision.
Either add a simple default configure or defines the more flexible policy of SOCKET_ID_ANY like
1) use the assigned default socket_id; 2) use current socket_id, if fail goto 1);
3) (weight)round robin across the malloc_heaps; 4) use current socket_id, if fail goto 3); and etc.
But on another side, the well-tuned application are usually NUMA friendly. Instead of using SOCKET_ID_ANY, it most often assigned the expected socket_id. Except getting the real current valid socket_id, The policy won't help on the affinity but mainly helps on the memory utilization.
I guess the worry comes from the case, after lots of memory allocation happens on socket 0, a new memzone_reserve fails when it definitely has to do it on socket 0 as well. In this case, either changes the default NUMA node or balance the allocation won't solve the problem, but respite it happening.
It's because the explicit assignment allocation (memzone_reserve, malloc with a specified socket_id) may not average balanced.
In reverse, if reserving all necessary memzone first, even malloc fails on default socket, it will try to get allocation from other NUMA node.
I think it's out of the scope of this patch series. On current moment, using the simplest way taking node 0 as default socket_id is not bad.
For more, we can post on separate patch and involved more on the discussion.
Thanks.
Quoted 13 lines
Neil
Quoted 10 lines
Quoted 9 lines
Neil
Quoted 7 lines
lib/librte_malloc/malloc_heap.h +0
-1} void * --1.8.1.4
PATCH v6 13/19 log: fix the gap to support non-EAL thread
In reply to a message not in the archiveFor those non-EAL thread, *_lcore_id* is invalid and probably larger than RTE_MAX_LCORE. The patch adds the check and allows only EAL thread using EAL per thread log level and log type. Others shares the global log level.
--- lib/librte_eal/common/eal_common_log.c | 17 +++++++++++++++-- lib/librte_eal/common/include/rte_log.h | 5 +++++ 2 files changed, 20 insertions(+), 2 deletions(-)
lib/librte_eal/common/eal_common_log.c +15 -2
@@ -193,11 +193,20 @@ rte_set_log_type(uint32_t type, int enable) rte_logs.type &= (~type); } +/* Get global log type */ +uint32_t +rte_get_log_type (void ) +{ +return rte_logs.type; +} +/* get the current loglevel for the message beeing processed */ int rte_log_cur_msg_loglevel (void ) {unsigned lcore_id; lcore_id =rte_lcore_id (); +if (lcore_id >=RTE_MAX_LCORE ) +return rte_get_log_level ();return log_cur_msg[lcore_id].loglevel; }
@@ -206,6 +215,8 @@ int rte_log_cur_msg_logtype(void) {unsigned lcore_id; lcore_id =rte_lcore_id (); +if (lcore_id >=RTE_MAX_LCORE ) +return rte_get_log_type ();return log_cur_msg[lcore_id].logtype; }
@@ -265,8 +276,10 @@ rte_vlog(__attribute__((unused)) uint32_t level,/* save loglevel and logtype in a global per-lcore variable */ lcore_id =rte_lcore_id (); - log_cur_msg[lcore_id].loglevel = level; - log_cur_msg[lcore_id].logtype = logtype; +if (lcore_id <RTE_MAX_LCORE ) { + log_cur_msg[lcore_id].loglevel = level; + log_cur_msg[lcore_id].logtype = logtype; + } ret =vfprintf (f, format, ap);fflush (f);
lib/librte_eal/common/include/rte_log.h +5 -0
@@ -144,6 +144,11 @@ uint32_t rte_get_log_level(void);void rte_set_log_type (uint32_t type,int enable);/** +* Get the global log type. +*/ +uint32_t rte_get_log_type (void ); + +/** * Get the current loglevel for the message being processed. * * Before calling the user-defined stream for logging, the log
Signature · 1 line
1.8.1.4
PATCH v6 14/19 eal: set _lcore_id and _socket_id to (-1) by default
In reply to a message not in the archiveFor those none EAL thread, *_lcore_id* shall always be LCORE_ID_ANY. The libraries using *_lcore_id* as index need to take care. *_socket_id* always be SOCKET_ID_ANY unitl the thread changes the affinity by rte_thread_set_affinity()
---
v5 changes:
define LCORE_ID_ANY as UINT32_MAX
lib/librte_eal/bsdapp/eal/eal_thread.c | 4 ++-- lib/librte_eal/common/include/rte_lcore.h | 4 ++-- lib/librte_eal/linuxapp/eal/eal_thread.c | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-)
lib/librte_eal/bsdapp/eal/eal_thread.c +2 -2
@@ -56,8 +56,8 @@#include "eal_private.h" #include "eal_thread.h" -RTE_DEFINE_PER_LCORE (unsigned, _lcore_id); -RTE_DEFINE_PER_LCORE (unsigned, _socket_id); +RTE_DEFINE_PER_LCORE (unsigned, _lcore_id) =LCORE_ID_ANY ; +RTE_DEFINE_PER_LCORE (unsigned, _socket_id) = (unsigned )SOCKET_ID_ANY ;RTE_DEFINE_PER_LCORE (rte_cpuset_t, _cpuset);/*
lib/librte_eal/common/include/rte_lcore.h +2 -2
@@ -48,7 +48,7 @@extern "C" {#endif -#define LCORE_ID_ANY -1/**< Any lcore. */ +#define LCORE_ID_ANY UINT32_MAX/**< Any lcore. */ #if defined(__linux__)typedef cpu_set_t rte_cpuset_t ;
@@ -87,7 +87,7 @@ RTE_DECLARE_PER_LCORE(rte_cpuset_t, _cpuset); /**< Per thread "cpuset". *//** * Return the ID of the execution unit we are running on. * @return -* Logical core ID +* Logical core ID(in EAL thread) or LCORE_ID_ANY(in non-EAL thread) */ static inline unsigned rte_lcore_id (void )
lib/librte_eal/linuxapp/eal/eal_thread.c +2 -2
@@ -56,8 +56,8 @@#include "eal_private.h" #include "eal_thread.h" -RTE_DEFINE_PER_LCORE (unsigned, _lcore_id); -RTE_DEFINE_PER_LCORE (unsigned, _socket_id); +RTE_DEFINE_PER_LCORE (unsigned, _lcore_id) =LCORE_ID_ANY ; +RTE_DEFINE_PER_LCORE (unsigned, _socket_id) = (unsigned )SOCKET_ID_ANY ;RTE_DEFINE_PER_LCORE (rte_cpuset_t, _cpuset);/*
Signature · 1 line
1.8.1.4
PATCH v6 15/19 eal: fix recursive spinlock in non-EAL thraed
In reply to a message not in the archiveIn non-EAL thread, lcore_id alrways be LCORE_ID_ANY. It cann't be used as unique id for recursive spinlock. Then use rte_gettid() to replace it.
--- lib/librte_eal/common/include/generic/rte_spinlock.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
lib/librte_eal/common/include/generic/rte_spinlock.h +2 -2
@@ -179,7 +179,7 @@ static inline void rte_spinlock_recursive_init(rte_spinlock_recursive_t *slr)*/ static inline void rte_spinlock_recursive_lock (rte_spinlock_recursive_t *slr) { -int id =rte_lcore_id (); +int id =rte_gettid ();if (slr->user != id) {rte_spinlock_lock (&slr->sl);
@@ -212,7 +212,7 @@ static inline void rte_spinlock_recursive_unlock(rte_spinlock_recursive_t *slr)*/ static inline int rte_spinlock_recursive_trylock (rte_spinlock_recursive_t *slr) { -int id =rte_lcore_id (); +int id =rte_gettid ();if (slr->user != id) {if (rte_spinlock_trylock (&slr->sl) ==0 )
Signature · 1 line
1.8.1.4
PATCH v6 16/19 mempool: add support to non-EAL thread
In reply to a message not in the archiveFor non-EAL thread, bypass per lcore cache, directly use ring pool. It allows using rte_mempool in either EAL thread or any user pthread. As in non-EAL thread, it directly rely on rte_ring and it's none preemptive. It doesn't suggest to run multi-pthread/cpu which compete the rte_mempool. It will get bad performance and has critical risk if scheduling policy is RT. Haven't found significant performance decrease by mempool_perf_test.
---
v6 changes:
rollback v5 changes
v5 changes:
check __lcore_id with LCORE_ID_ANY instead of RTE_MAX_LCORE
lib/librte_mempool/rte_mempool.h | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-)
lib/librte_mempool/rte_mempool.h +11 -7
@@ -198,10 +198,12 @@ struct rte_mempool {* Number to add to the object-oriented statistics. */ #ifdef RTE_LIBRTE_MEMPOOL_DEBUG -#define __MEMPOOL_STAT_ADD (mp, name, n) do { \ - unsigned __lcore_id = rte_lcore_id(); \ - mp->stats[__lcore_id].name##_objs += n; \ - mp->stats[__lcore_id].name##_bulk += 1; \ +#define __MEMPOOL_STAT_ADD (mp, name, n) do { \ + unsigned __lcore_id = rte_lcore_id(); \ + if (__lcore_id < RTE_MAX_LCORE) { \ + mp->stats[__lcore_id].name##_objs += n; \ + mp->stats[__lcore_id].name##_bulk += 1; \ + } \ } while(0)#else #define __MEMPOOL_STAT_ADD (mp, name, n) do {} while(0)
@@ -767,8 +769,9 @@ __mempool_put_bulk(struct rte_mempool *mp, void * const *obj_table,__MEMPOOL_STAT_ADD (mp, put, n);#if RTE_MEMPOOL_CACHE_MAX_SIZE >0 -/* cache is not enabled or single producer */ -if (unlikely (cache_size ==0 || is_mp ==0 )) +/* cache is not enabled or single producer or none EAL thread */ +if (unlikely (cache_size ==0 || is_mp ==0 || + lcore_id >=RTE_MAX_LCORE )) goto ring_enqueue;/* Go straight to ring if put would overflow mem allocated for cache */
@@ -952,7 +955,8 @@ __mempool_get_bulk(struct rte_mempool *mp, void **obj_table,uint32_t cache_size = mp->cache_size;/* cache is not enabled or single consumer */ -if (unlikely (cache_size ==0 || is_mc ==0 || n >= cache_size)) +if (unlikely (cache_size ==0 || is_mc ==0 || + n >= cache_size || lcore_id >=RTE_MAX_LCORE )) goto ring_dequeue; cache = &mp->local_cache[lcore_id];
Signature · 1 line
1.8.1.4
PATCH v6 17/19 ring: add support to non-EAL thread
In reply to a message not in the archivering debug stat won't take care non-EAL thread.
---
v6 changes:
rollback v5 changes
v5 changes:
check __lcore_id with LCORE_ID_ANY instead of RTE_MAX_LCORE
lib/librte_ring/rte_ring.h | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-)
lib/librte_ring/rte_ring.h +6 -4
@@ -188,10 +188,12 @@ struct rte_ring {* The number to add to the object-oriented statistics. */ #ifdef RTE_LIBRTE_RING_DEBUG -#define __RING_STAT_ADD (r, name, n) do { \ - unsigned __lcore_id = rte_lcore_id(); \ - r->stats[__lcore_id].name##_objs += n; \ - r->stats[__lcore_id].name##_bulk += 1; \ +#define __RING_STAT_ADD (r, name, n) do { \ + unsigned __lcore_id = rte_lcore_id(); \ + if (__lcore_id < RTE_MAX_LCORE) { \ + r->stats[__lcore_id].name##_objs += n; \ + r->stats[__lcore_id].name##_bulk += 1; \ + } \ } while(0)#else #define __RING_STAT_ADD (r, name, n) do {} while(0)
Signature · 1 line
1.8.1.4
PATCH v6 18/19 ring: add sched_yield to avoid spin forever
In reply to a message not in the archiveAdd a sched_yield() syscall if the thread spins for too long, waiting other thread to finish its operations on the ring. That gives pre-empted thread a chance to proceed and finish with ring enqnue/dequeue operation.
The purpose is to reduce contention on the ring. By ring_perf_test, it doesn't shows additional perf penalty.
---
v6 changes:
rename RTE_RING_PAUSE_REP to RTE_RING_PAUSE_REP_COUNT set default value as '0' in configure file
v5 changes:
add RTE_RING_PAUSE_REP to config file
v4 changes:
update and add more comments on sched_yield()
v3 changes:
new patch adding sched_yield() in rte_ring to avoid long spin
config/common_bsdapp | 1 + config/common_linuxapp | 1 + lib/librte_ring/rte_ring.h | 31 +++++++++++++++++++++++++++---- 3 files changed, 29 insertions(+), 4 deletions(-)
config/common_bsdapp +1 -0
@@ -234,6 +234,7 @@ CONFIG_RTE_PMD_PACKET_PREFETCH=y CONFIG_RTE_LIBRTE_RING=y CONFIG_RTE_LIBRTE_RING_DEBUG=n CONFIG_RTE_RING_SPLIT_PROD_CONS=n +CONFIG_RTE_RING_PAUSE_REP_COUNT=0 # # Compile librte_mempool
config/common_linuxapp +1 -0
@@ -242,6 +242,7 @@ CONFIG_RTE_PMD_PACKET_PREFETCH=y CONFIG_RTE_LIBRTE_RING=y CONFIG_RTE_LIBRTE_RING_DEBUG=n CONFIG_RTE_RING_SPLIT_PROD_CONS=n +CONFIG_RTE_RING_PAUSE_REP_COUNT=0 # # Compile librte_mempool
lib/librte_ring/rte_ring.h +27 -4
@@ -127,6 +127,11 @@ struct rte_ring_debug_stats {#define RTE_RING_NAMESIZE 32/**< The maximum length of a ring name. */ #define RTE_RING_MZ_PREFIX "RG_" +#ifndef RTE_RING_PAUSE_REP_COUNT +#define RTE_RING_PAUSE_REP_COUNT 0/**< yield after pause num of times, no yield +* if RTE_RING_PAUSE_REP not defined. */ +#endif +/** * An RTE ring structure. *
@@ -410,7 +415,7 @@ __rte_ring_mp_do_enqueue(struct rte_ring *r, void * const *obj_table,uint32_t cons_tail, free_entries;const unsigned max = n;int success; -unsigned i; +unsigned i, rep =0 ;uint32_t mask = r->prod.mask;int ret;
@@ -468,9 +473,18 @@ __rte_ring_mp_do_enqueue(struct rte_ring *r, void * const *obj_table,* If there are other enqueues in progress that preceded us, * we need to wait for them to complete */ -while (unlikely (r->prod.tail != prod_head)) +while (unlikely (r->prod.tail != prod_head)) {rte_pause (); +/* Set RTE_RING_PAUSE_REP_COUNT to avoid spin too long waiting +* for other thread finish. It gives pre-empted thread a chance +* to proceed and finish with ring denqnue operation. */ +if (RTE_RING_PAUSE_REP_COUNT && + ++rep ==RTE_RING_PAUSE_REP_COUNT ) { + rep =0 ; +sched_yield (); + } + } r->prod.tail = prod_next;return ret; }
@@ -589,7 +603,7 @@ __rte_ring_mc_do_dequeue(struct rte_ring *r, void **obj_table,uint32_t cons_next, entries;const unsigned max = n;int success; -unsigned i; +unsigned i, rep =0 ;uint32_t mask = r->prod.mask;/* move cons.head atomically */
@@ -634,9 +648,18 @@ __rte_ring_mc_do_dequeue(struct rte_ring *r, void **obj_table,* If there are other dequeues in progress that preceded us, * we need to wait for them to complete */ -while (unlikely (r->cons.tail != cons_head)) +while (unlikely (r->cons.tail != cons_head)) {rte_pause (); +/* Set RTE_RING_PAUSE_REP_COUNT to avoid spin too long waiting +* for other thread finish. It gives pre-empted thread a chance +* to proceed and finish with ring denqnue operation. */ +if (RTE_RING_PAUSE_REP_COUNT && + ++rep ==RTE_RING_PAUSE_REP_COUNT ) { + rep =0 ; +sched_yield (); + } + }__RING_STAT_ADD (r, deq_success, n); r->cons.tail = cons_next;
Signature · 1 line
1.8.1.4
PATCH v6 19/19 timer: add support to non-EAL thread
In reply to a message not in the archiveAllow to setup timers only for EAL (lcore) threads (__lcore_id < MAX_LCORE_ID). E.g. – dynamically created thread will be able to reset/stop timer for lcore thread, but it will be not allowed to setup timer for itself or another non-lcore thread. rte_timer_manage() for non-lcore thread would simply do nothing and return straightway.
---
v6 changes:
use 'RTE_MAX_LCORE' to check the EAL thread with valid lcore_id. use 'LCORE_ID_ANY' for any unspecified lcore_id assignment.
v5 changes:
add assert in rte_timer_manage
remove duplicate check in timer_set_config_state
lib/librte_timer/rte_timer.c | 32 +++++++++++++++++++++++--------- lib/librte_timer/rte_timer.h | 4 ++-- 2 files changed, 25 insertions(+), 11 deletions(-)
lib/librte_timer/rte_timer.c +23 -9
@@ -35,6 +35,7 @@#include <stdio.h> #include <stdint.h> #include <inttypes.h> +#include <assert.h> #include <rte_atomic.h> #include <rte_common.h>
@@ -79,9 +80,10 @@ static struct priv_timer priv_timer[RTE_MAX_LCORE];/* when debug is enabled, store some statistics */ #ifdef RTE_LIBRTE_TIMER_DEBUG -#define __TIMER_STAT_ADD (name, n) do { \ - unsigned __lcore_id = rte_lcore_id(); \ - priv_timer[__lcore_id].stats.name += (n); \ +#define __TIMER_STAT_ADD (name, n) do { \ + unsigned __lcore_id = rte_lcore_id(); \ + if (__lcore_id < RTE_MAX_LCORE) \ + priv_timer[__lcore_id].stats.name += (n); \ } while(0)#else #define __TIMER_STAT_ADD (name, n) do {} while(0)
@@ -135,7 +137,7 @@ timer_set_config_state(struct rte_timer *tim,/* timer is running on another core, exit */ if (prev_status.state ==RTE_TIMER_RUNNING && - (unsigned )prev_status.owner != lcore_id) + prev_status.owner != (uint16_t )lcore_id)return -1 ;/* timer is being configured on another core */
@@ -366,9 +368,16 @@ __rte_timer_reset(struct rte_timer *tim, uint64_t expire,/* round robin for tim_lcore */ if (tim_lcore == (unsigned )LCORE_ID_ANY ) { - tim_lcore =rte_get_next_lcore (priv_timer[lcore_id].prev_lcore, -0 ,1 ); - priv_timer[lcore_id].prev_lcore = tim_lcore; +if (lcore_id <RTE_MAX_LCORE ) { +/* EAL thread with valid lcore_id */ + tim_lcore =rte_get_next_lcore ( + priv_timer[lcore_id].prev_lcore, +0 ,1 ); + priv_timer[lcore_id].prev_lcore = tim_lcore; + }else +/* non-EAL thread do not run rte_timer_manage(), +* so schedule the timer on the first enabled lcore. */ + tim_lcore =rte_get_next_lcore (LCORE_ID_ANY ,0 ,1 ); }/* wait that the timer is in correct status before update,
@@ -378,7 +387,8 @@ __rte_timer_reset(struct rte_timer *tim, uint64_t expire,return -1 ;__TIMER_STAT_ADD (reset,1 ); -if (prev_status.state ==RTE_TIMER_RUNNING ) { +if (prev_status.state ==RTE_TIMER_RUNNING && + lcore_id <RTE_MAX_LCORE ) { priv_timer[lcore_id].updated =1 ; }
@@ -455,7 +465,8 @@ rte_timer_stop(struct rte_timer *tim)return -1 ;__TIMER_STAT_ADD (stop,1 ); -if (prev_status.state ==RTE_TIMER_RUNNING ) { +if (prev_status.state ==RTE_TIMER_RUNNING && + lcore_id <RTE_MAX_LCORE ) { priv_timer[lcore_id].updated =1 ; }
@@ -499,6 +510,9 @@ void rte_timer_manage(void)uint64_t cur_time;int i, ret; +/* timer manager only runs on EAL thread with valid lcore_id */ +assert (lcore_id <RTE_MAX_LCORE ); +__TIMER_STAT_ADD (manage,1 );/* optimize for the case where per-cpu list is empty */ if (priv_timer[lcore_id].pending_head.sl_next[0 ] ==NULL )
lib/librte_timer/rte_timer.h +2 -2
@@ -76,7 +76,7 @@ extern "C" {#define RTE_TIMER_RUNNING 2/**< State: timer function is running. */ #define RTE_TIMER_CONFIG 3/**< State: timer is being configured. */ -#define RTE_TIMER_NO_OWNER -1/**< Timer has no owner. */ +#define RTE_TIMER_NO_OWNER -2/**< Timer has no owner. */ /** * Timer type: Periodic or single (one-shot).
@@ -310,7 +310,7 @@ int rte_timer_pending(struct rte_timer *tim);/** * Manage the timer list and execute callback functions. * -* This function must be called periodically from all cores +* This function must be called periodically from EAL lcores * main_loop(). It browses the list of pending timers and runs all * timers that are expired. *
Signature · 1 line
1.8.1.4
Olivier MATZ
Acked-byHi,
Quoted 75 lines · Cunming Liang
v6 changes:
renameRTE_RING_PAUSE_REP(_COUNT)and set default to 0 rollback to useRTE_MAX_LCOREwhen checking validlcore_idfor EAL threadv5 changes:
reorder some patch and split into addtional two patchesrte_thread_get_affinity()return type change to avoid addRTE_RING_PAUSE_REPinto config and by default turn offv4 changes:
new patch fixingstrnlen()invalid return in 32bit icc [03/17] update and add more comments onsched_yield()[16/17]v3 changes:
new patch addingsched_yield()inrte_ringto avoid long spin [16/17]v2 changes:
add '<number>-<number>' support for EAL option '--lcores' [02/17]The patch series contain the enhancements of EAL and fixes for libraries
to run multi-pthreads(either EAL or non-EAL thread) per physical core.
Two major changes list as below:
- Extend the core affinity of each EAL thread to 1:n.
Each lcore stands for a EAL thread rather than a logical core.
The change adds new EAL option to allow static lcore to cpuset assginment. Then a lcore(EAL thread) affinity to a cpuset, original 1:1 mapping is the special case.
- Fix the libraries to allow running on any non-EAL thread.
It fix the gaps running libraries in non-EAL thread(dynamic created by user). Each fix libraries take care the case ofrte_lcore_id()>=RTE_MAX_LCORE.Thanks a million for the comments from Konstantin, Bruce, Mirek and Stephen in RFC review.
Cunming Liang (19):
eal: add cpuset into per EAL threadlcore_config
eal: fixPAGE_SIZEredefine complaint on freebsd
eal: new eal option '--lcores' for cpu assignment
eal: fix wrongstrnlen()return value in 32bit icc
eal: add support parsingsocket_idfrom cpuset
eal: new TLS definition and API declaration
eal: addeal_common_thread.cfor common thread API
eal: standardize init sequence between linux and bsd
eal: addrte_gettid()to acquire unique system tid
eal: apply affinity of EAL thread by assigned cpuset
enic: fix re-define freebsd compile complain
malloc: fix the issue ofSOCKET_ID_ANY
log: fix the gap to support non-EAL thread
eal: set_lcore_idand_socket_idto (-1) by default
eal: fix recursive spinlock in non-EAL thraed
mempool: add support to non-EAL thread
ring: add support to non-EAL thread
ring: addsched_yieldto avoid spin forever
timer: add support to non-EAL threadconfig/common_bsdapp | 1 + config/common_linuxapp | 1 + lib/librte_eal/bsdapp/eal/Makefile | 1 + lib/librte_eal/bsdapp/eal/eal.c | 14 +- lib/librte_eal/bsdapp/eal/eal_lcore.c | 14 + lib/librte_eal/bsdapp/eal/eal_memory.c | 8 +- lib/librte_eal/bsdapp/eal/eal_thread.c | 77 ++---- lib/librte_eal/common/eal_common_log.c | 17 +- lib/librte_eal/common/eal_common_options.c | 308 ++++++++++++++++++++- lib/librte_eal/common/eal_common_thread.c | 150 ++++++++++ lib/librte_eal/common/eal_options.h | 2 + lib/librte_eal/common/eal_thread.h | 47 ++++ .../common/include/generic/rte_spinlock.h | 4 +- lib/librte_eal/common/include/rte_eal.h | 27 ++ lib/librte_eal/common/include/rte_lcore.h | 40 ++- lib/librte_eal/common/include/rte_log.h | 5 + lib/librte_eal/linuxapp/eal/Makefile | 4 + lib/librte_eal/linuxapp/eal/eal.c | 8 +- lib/librte_eal/linuxapp/eal/eal_lcore.c | 15 +- lib/librte_eal/linuxapp/eal/eal_thread.c | 77 ++---- lib/librte_malloc/malloc_heap.h | 7 +- lib/librte_mempool/rte_mempool.h | 18 +-
Quoted 9 lines
lib/librte_pmd_enic/enic.h | 4 +- lib/librte_pmd_enic/enic_compat.h | 2 +- lib/librte_pmd_enic/vnic/vnic_dev.c | 6 +- lib/librte_ring/rte_ring.h | 41 ++- lib/librte_timer/rte_timer.c | 32 ++- lib/librte_timer/rte_timer.h | 4 +- 28 files changed, 765 insertions(+), 169 deletions(-) create mode 100644 lib/librte_eal/common/eal_common_thread.c
Series:
Maybe a doc update will be required, could you have a look at it?
Another question, is it planned to add some unit tests for this feature?
Thanks!
A message that is not in the archive (sent off-list or not yet received): [email protected]
Hi,
Quoted 97 lines
-----Original Message-----
From: Olivier MATZ [mailto:[email protected]]
Sent: Friday, February 13, 2015 6:06 PM
To: Liang, Cunming; [email protected]
Subject: Re: [dpdk-dev] [PATCH v6 00/19] support multi-pthread per coreHi,
Quoted 19 lines · Cunming Liang
v6 changes:
renameRTE_RING_PAUSE_REP(_COUNT)and set default to 0 rollback to useRTE_MAX_LCOREwhen checking validlcore_idfor EAL threadv5 changes:
reorder some patch and split into addtional two patchesrte_thread_get_affinity()return type change to avoid addRTE_RING_PAUSE_REPinto config and by default turn offv4 changes:
new patch fixingstrnlen()invalid return in 32bit icc [03/17] update and add more comments onsched_yield()[16/17]v3 changes:
new patch addingsched_yield()inrte_ringto avoid long spin [16/17]v2 changes:
add '<number>-<number>' support for EAL option '--lcores' [02/17]Quoted 7 lines
The patch series contain the enhancements of EAL and fixes for libraries to run multi-pthreads(either EAL or non-EAL thread) per physical core. Two major changes list as below:
- Extend the core affinity of each EAL thread to 1:n.
Each lcore stands for a EAL thread rather than a logical core.
The change adds new EAL option to allow static lcore to cpuset assginment. Then a lcore(EAL thread) affinity to a cpuset, original 1:1 mapping is the specialcase.
Quoted 5 lines
- Fix the libraries to allow running on any non-EAL thread.
It fix the gaps running libraries in non-EAL thread(dynamic created by user). Each fix libraries take care the case ofrte_lcore_id()>=RTE_MAX_LCORE.Thanks a million for the comments from Konstantin, Bruce, Mirek and Stephen
in RFC review.
Quoted 22 lines
Cunming Liang (19):
eal: add cpuset into per EAL threadlcore_config
eal: fixPAGE_SIZEredefine complaint on freebsd
eal: new eal option '--lcores' for cpu assignment
eal: fix wrongstrnlen()return value in 32bit icc
eal: add support parsingsocket_idfrom cpuset
eal: new TLS definition and API declaration
eal: addeal_common_thread.cfor common thread API
eal: standardize init sequence between linux and bsd
eal: addrte_gettid()to acquire unique system tid
eal: apply affinity of EAL thread by assigned cpuset
enic: fix re-define freebsd compile complain
malloc: fix the issue ofSOCKET_ID_ANY
log: fix the gap to support non-EAL thread
eal: set_lcore_idand_socket_idto (-1) by default
eal: fix recursive spinlock in non-EAL thraed
mempool: add support to non-EAL thread
ring: add support to non-EAL thread
ring: addsched_yieldto avoid spin forever
timer: add support to non-EAL threadQuoted 9 lines
config/common_bsdapp | 1 + config/common_linuxapp | 1 + lib/librte_eal/bsdapp/eal/Makefile | 1 + lib/librte_eal/bsdapp/eal/eal.c | 14 +- lib/librte_eal/bsdapp/eal/eal_lcore.c | 14 + lib/librte_eal/bsdapp/eal/eal_memory.c | 8 +- lib/librte_eal/bsdapp/eal/eal_thread.c | 77 ++---- lib/librte_eal/common/eal_common_log.c | 17 +- lib/librte_eal/common/eal_common_options.c | 308++++++++++++++++++++-
Quoted 13 lines
lib/librte_eal/common/eal_common_thread.c | 150 ++++++++++ lib/librte_eal/common/eal_options.h | 2 + lib/librte_eal/common/eal_thread.h | 47 ++++ .../common/include/generic/rte_spinlock.h | 4 +- lib/librte_eal/common/include/rte_eal.h | 27 ++ lib/librte_eal/common/include/rte_lcore.h | 40 ++- lib/librte_eal/common/include/rte_log.h | 5 + lib/librte_eal/linuxapp/eal/Makefile | 4 + lib/librte_eal/linuxapp/eal/eal.c | 8 +- lib/librte_eal/linuxapp/eal/eal_lcore.c | 15 +- lib/librte_eal/linuxapp/eal/eal_thread.c | 77 ++---- lib/librte_malloc/malloc_heap.h | 7 +- lib/librte_mempool/rte_mempool.h | 18 +-Quoted 9 lines
lib/librte_pmd_enic/enic.h | 4 +- lib/librte_pmd_enic/enic_compat.h | 2 +- lib/librte_pmd_enic/vnic/vnic_dev.c | 6 +- lib/librte_ring/rte_ring.h | 41 ++- lib/librte_timer/rte_timer.c | 32 ++- lib/librte_timer/rte_timer.h | 4 +- 28 files changed, 765 insertions(+), 169 deletions(-) create mode 100644 lib/librte_eal/common/eal_common_thread.c
Quoted 2 lines
Series:
Acked-by Olivier Matz <[email protected]>
[LCM] Thanks for all the comments and suggestion.
Quoted 2 lines
Maybe a doc update will be required, could you have a look at it?
[LCM] Yes, I'm writing it. Will send a separate patch for doc update.
Quoted 3 lines
Another question, is it planned to add some unit tests for this feature?
[LCM] Do you means add EAL flags check in 'test_eal_flags.c' ?
I can add that, do you suggest to put them in this patch series or in a separate one ?
Quoted 2 lines
Thanks!
Ananyev, Konstantin
Acked-by Konstantin AnanyevQuoted 84 lines
-----Original Message-----
From: Liang, Cunming
Sent: Friday, February 13, 2015 1:38 AM
To: [email protected]
Cc: Ananyev, Konstantin; Liang, Cunming
Subject: [PATCH v6 00/19] support multi-pthread per corev6 changes:
renameRTE_RING_PAUSE_REP(_COUNT)and set default to 0 rollback to useRTE_MAX_LCOREwhen checking validlcore_idfor EAL threadv5 changes:
reorder some patch and split into addtional two patchesrte_thread_get_affinity()return type change to avoid addRTE_RING_PAUSE_REPinto config and by default turn offv4 changes:
new patch fixingstrnlen()invalid return in 32bit icc [03/17] update and add more comments onsched_yield()[16/17]v3 changes:
new patch addingsched_yield()inrte_ringto avoid long spin [16/17]v2 changes:
add '<number>-<number>' support for EAL option '--lcores' [02/17]The patch series contain the enhancements of EAL and fixes for libraries
to run multi-pthreads(either EAL or non-EAL thread) per physical core.
Two major changes list as below:
- Extend the core affinity of each EAL thread to 1:n.
Each lcore stands for a EAL thread rather than a logical core.
The change adds new EAL option to allow static lcore to cpuset assginment. Then a lcore(EAL thread) affinity to a cpuset, original 1:1 mapping is the special case.
- Fix the libraries to allow running on any non-EAL thread.
It fix the gaps running libraries in non-EAL thread(dynamic created by user). Each fix libraries take care the case ofrte_lcore_id()>=RTE_MAX_LCORE.Thanks a million for the comments from Konstantin, Bruce, Mirek and Stephen in RFC review.
Cunming Liang (19):
eal: add cpuset into per EAL threadlcore_config
eal: fixPAGE_SIZEredefine complaint on freebsd
eal: new eal option '--lcores' for cpu assignment
eal: fix wrongstrnlen()return value in 32bit icc
eal: add support parsingsocket_idfrom cpuset
eal: new TLS definition and API declaration
eal: addeal_common_thread.cfor common thread API
eal: standardize init sequence between linux and bsd
eal: addrte_gettid()to acquire unique system tid
eal: apply affinity of EAL thread by assigned cpuset
enic: fix re-define freebsd compile complain
malloc: fix the issue ofSOCKET_ID_ANY
log: fix the gap to support non-EAL thread
eal: set_lcore_idand_socket_idto (-1) by default
eal: fix recursive spinlock in non-EAL thraed
mempool: add support to non-EAL thread
ring: add support to non-EAL thread
ring: addsched_yieldto avoid spin forever
timer: add support to non-EAL threadconfig/common_bsdapp | 1 + config/common_linuxapp | 1 + lib/librte_eal/bsdapp/eal/Makefile | 1 + lib/librte_eal/bsdapp/eal/eal.c | 14 +- lib/librte_eal/bsdapp/eal/eal_lcore.c | 14 + lib/librte_eal/bsdapp/eal/eal_memory.c | 8 +- lib/librte_eal/bsdapp/eal/eal_thread.c | 77 ++---- lib/librte_eal/common/eal_common_log.c | 17 +- lib/librte_eal/common/eal_common_options.c | 308 ++++++++++++++++++++- lib/librte_eal/common/eal_common_thread.c | 150 ++++++++++ lib/librte_eal/common/eal_options.h | 2 + lib/librte_eal/common/eal_thread.h | 47 ++++ .../common/include/generic/rte_spinlock.h | 4 +- lib/librte_eal/common/include/rte_eal.h | 27 ++ lib/librte_eal/common/include/rte_lcore.h | 40 ++- lib/librte_eal/common/include/rte_log.h | 5 + lib/librte_eal/linuxapp/eal/Makefile | 4 + lib/librte_eal/linuxapp/eal/eal.c | 8 +- lib/librte_eal/linuxapp/eal/eal_lcore.c | 15 +- lib/librte_eal/linuxapp/eal/eal_thread.c | 77 ++---- lib/librte_malloc/malloc_heap.h | 7 +- lib/librte_mempool/rte_mempool.h | 18 +-
Quoted 9 lines
lib/librte_pmd_enic/enic.h | 4 +- lib/librte_pmd_enic/enic_compat.h | 2 +- lib/librte_pmd_enic/vnic/vnic_dev.c | 6 +- lib/librte_ring/rte_ring.h | 41 ++- lib/librte_timer/rte_timer.c | 32 ++- lib/librte_timer/rte_timer.h | 4 +- 28 files changed, 765 insertions(+), 169 deletions(-) create mode 100644 lib/librte_eal/common/eal_common_thread.c
Quoted 2 lines
--
1.8.1.4
v7 cover support multi-pthread per core
In reply to a message not in the archivev7 changes:
update EAL version map for new public EAL API rollback to use strnlen() passing EAL core option
v6 changes:
rename RTE_RING_PAUSE_REP(_COUNT) and set default to 0 rollback to use RTE_MAX_LCORE when checking valid lcore_id for EAL thread
v5 changes:
reorder some patch and split into addtional two patches rte_thread_get_affinity() return type change to avoid add RTE_RING_PAUSE_REP into config and by default turn off
v4 changes:
new patch fixing strnlen() invalid return in 32bit icc [03/17] update and add more comments on sched_yield() [16/17]
v3 changes:
new patch adding sched_yield() in rte_ring to avoid long spin [16/17]
v2 changes:
add '<number>-<number>' support for EAL option '--lcores' [02/17]
The patch series contain the enhancements of EAL and fixes for libraries
to run multi-pthreads(either EAL or non-EAL thread) per physical core.
Two major changes list as below:
- Extend the core affinity of each EAL thread to 1:n.
Each lcore stands for a EAL thread rather than a logical core.
The change adds new EAL option to allow static lcore to cpuset assginment. Then a lcore(EAL thread) affinity to a cpuset, original 1:1 mapping is the special case.
- Fix the libraries to allow running on any non-EAL thread.
It fix the gaps running libraries in non-EAL thread(dynamic created by user). Each fix libraries take care the case of rte_lcore_id() >= RTE_MAX_LCORE.
Thanks a million for the comments from Konstantin, Bruce, Mirek and Stephen in RFC review.
Cunming Liang (19):
eal: add cpuset into per EAL thread lcore_config
eal: fix PAGE_SIZE redefine complaint on freebsd
eal: new eal option '--lcores' for cpu assignment
eal: fix wrong strnlen() return value in 32bit icc
eal: add support parsing socket_id from cpuset
eal: new TLS definition and API declaration
eal: add eal_common_thread.c for common thread API
eal: standardize init sequence between linux and bsd
eal: add rte_gettid() to acquire unique system tid
eal: apply affinity of EAL thread by assigned cpuset
enic: fix re-define freebsd compile complain
malloc: fix the issue of SOCKET_ID_ANY
log: fix the gap to support non-EAL thread
eal: set _lcore_id and _socket_id to (-1) by default
eal: fix recursive spinlock in non-EAL thraed
mempool: add support to non-EAL thread
ring: add support to non-EAL thread
ring: add sched_yield to avoid spin forever
timer: add support to non-EAL thread
config/common_bsdapp | 1 + config/common_linuxapp | 1 + lib/librte_eal/bsdapp/eal/Makefile | 1 + lib/librte_eal/bsdapp/eal/eal.c | 14 +- lib/librte_eal/bsdapp/eal/eal_lcore.c | 14 + lib/librte_eal/bsdapp/eal/eal_memory.c | 8 +- lib/librte_eal/bsdapp/eal/eal_thread.c | 77 ++--- lib/librte_eal/bsdapp/eal/rte_eal_version.map | 2 + lib/librte_eal/common/eal_common_log.c | 17 +- lib/librte_eal/common/eal_common_options.c | 309 ++++++++++++++++++++- lib/librte_eal/common/eal_common_thread.c | 150 ++++++++++ lib/librte_eal/common/eal_options.h | 2 + lib/librte_eal/common/eal_thread.h | 47 ++++ .../common/include/generic/rte_spinlock.h | 4 +- lib/librte_eal/common/include/rte_eal.h | 27 ++ lib/librte_eal/common/include/rte_lcore.h | 40 ++- lib/librte_eal/common/include/rte_log.h | 5 + lib/librte_eal/linuxapp/eal/Makefile | 4 + lib/librte_eal/linuxapp/eal/eal.c | 8 +- lib/librte_eal/linuxapp/eal/eal_lcore.c | 15 +- lib/librte_eal/linuxapp/eal/eal_thread.c | 77 ++--- lib/librte_eal/linuxapp/eal/rte_eal_version.map | 2 + lib/librte_malloc/malloc_heap.h | 7 +- lib/librte_mempool/rte_mempool.h | 18 +- lib/librte_pmd_enic/enic.h | 4 +- lib/librte_pmd_enic/enic_compat.h | 2 +- lib/librte_pmd_enic/vnic/vnic_dev.c | 6 +- lib/librte_ring/rte_ring.h | 41 ++- lib/librte_timer/rte_timer.c | 32 ++- lib/librte_timer/rte_timer.h | 4 +- 30 files changed, 770 insertions(+), 169 deletions(-) create mode 100644 lib/librte_eal/common/eal_common_thread.c
Signature · 1 line
1.8.1.4
A message that is not in the archive (sent off-list or not yet received): 1423970145-31985-1-git-send-email-cunming.liang-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org
PATCH v7 1/19 eal: add cpuset into per EAL thread lcore_config
The patch adds 'cpuset' into per-lcore configure 'lcore_config[]', as the lcore no longer always 1:1 pinning with physical cpu. The lcore now stands for a EAL thread rather than a logical cpu.
It doesn't change the default behavior of 1:1 mapping, but allows to affinity the EAL thread to multiple cpus.
---
v5 changes:
separate eal_memory.c to the new patch
lib/librte_eal/bsdapp/eal/eal_lcore.c | 7 +++++++ lib/librte_eal/common/include/rte_lcore.h | 8 ++++++++ lib/librte_eal/linuxapp/eal/Makefile | 1 + lib/librte_eal/linuxapp/eal/eal_lcore.c | 8 ++++++++ 4 files changed, 24 insertions(+)
lib/librte_eal/bsdapp/eal/eal_lcore.c +7 -0
@@ -76,11 +76,18 @@ rte_eal_cpu_init(void)* ones and enable them by default. */ for (lcore_id =0 ; lcore_id <RTE_MAX_LCORE ; lcore_id++) { +/* init cpuset for per lcore config */ +CPU_ZERO (&lcore_config[lcore_id].cpuset); + lcore_config[lcore_id].detected = (lcore_id < ncpus);if (lcore_config[lcore_id].detected ==0 ) { config->lcore_role[lcore_id] =ROLE_OFF ;continue ; } + +/* By default, lcore 1:1 map to cpu id */ +CPU_SET (lcore_id, &lcore_config[lcore_id].cpuset); +/* By default, each detected core is enabled */ config->lcore_role[lcore_id] =ROLE_RTE ; lcore_config[lcore_id].core_id =cpu_core_id (lcore_id);
lib/librte_eal/common/include/rte_lcore.h +8 -0
@@ -50,6 +50,13 @@ extern "C" {#define LCORE_ID_ANY -1/**< Any lcore. */ +#if defined(__linux__) +typedef cpu_set_t rte_cpuset_t ; +#elif defined(__FreeBSD__) +#include <pthread_np.h> +typedef cpuset_t rte_cpuset_t ; +#endif +/** * Structure storing internal configuration (per-lcore) */
@@ -65,6 +72,7 @@ struct lcore_config {unsigned socket_id;/**< physical socket id for this lcore */ unsigned core_id;/**< core number on socket for this lcore */ int core_index;/**< relative index, starting from 0 */ +rte_cpuset_t cpuset;/**< cpu set which the lcore affinity to */ };/**
lib/librte_eal/linuxapp/eal/Makefile +1 -0
@@ -91,6 +91,7 @@ SRCS-$(CONFIG_RTE_LIBRTE_EAL_LINUXAPP) += eal_common_dev.c SRCS-$(CONFIG_RTE_LIBRTE_EAL_LINUXAPP) += eal_common_options.c CFLAGS_eal.o := -D_GNU_SOURCE +CFLAGS_eal_lcore.o := -D_GNU_SOURCE CFLAGS_eal_thread.o := -D_GNU_SOURCE CFLAGS_eal_log.o := -D_GNU_SOURCE CFLAGS_eal_common_log.o := -D_GNU_SOURCE
lib/librte_eal/linuxapp/eal/eal_lcore.c +8 -0
@@ -158,11 +158,19 @@ rte_eal_cpu_init(void)* ones and enable them by default. */ for (lcore_id =0 ; lcore_id <RTE_MAX_LCORE ; lcore_id++) { +/* init cpuset for per lcore config */ +CPU_ZERO (&lcore_config[lcore_id].cpuset); + +/* in 1:1 mapping, record related cpu detected state */ lcore_config[lcore_id].detected =cpu_detected (lcore_id);if (lcore_config[lcore_id].detected ==0 ) { config->lcore_role[lcore_id] =ROLE_OFF ;continue ; } + +/* By default, lcore 1:1 map to cpu id */ +CPU_SET (lcore_id, &lcore_config[lcore_id].cpuset); +/* By default, each detected core is enabled */ config->lcore_role[lcore_id] =ROLE_RTE ; lcore_config[lcore_id].core_id =cpu_core_id (lcore_id);
Signature · 1 line
1.8.1.4
PATCH v7 2/19 eal: fix PAGE_SIZE redefine complaint on freebsd
In reply to a message not in the archive--- lib/librte_eal/bsdapp/eal/eal_memory.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-)
lib/librte_eal/bsdapp/eal/eal_memory.c +5 -3
@@ -45,7 +45,7 @@#include "eal_internal_cfg.h" #include "eal_filesystem.h" -#define PAGE_SIZE (sysconf(_SC_PAGESIZE)) +#define EAL_PAGE_SIZE (sysconf(_SC_PAGESIZE))/* * Get physical address of any mapped virtual address in the current process.
@@ -93,7 +93,8 @@ rte_eal_contigmem_init(void)char physaddr_str[64 ]; addr =mmap (NULL , hpi->hugepage_sz,PROT_READ |PROT_WRITE , -MAP_SHARED , hpi->lock_descriptor, j *PAGE_SIZE ); +MAP_SHARED , hpi->lock_descriptor, + j *EAL_PAGE_SIZE );if (addr ==MAP_FAILED ) {RTE_LOG (ERR ,EAL ,"Failed to mmap buffer %u from %s\n" , j, hpi->hugedir);
@@ -167,7 +168,8 @@ rte_eal_contigmem_attach(void)struct rte_memseg *seg = &mcfg->memseg[i]; addr =mmap (seg->addr, hpi->hugepage_sz,PROT_READ |PROT_WRITE , -MAP_SHARED |MAP_FIXED , fd_hugepage, i *PAGE_SIZE ); +MAP_SHARED |MAP_FIXED , fd_hugepage, + i *EAL_PAGE_SIZE );if (addr ==MAP_FAILED || addr != seg->addr) {RTE_LOG (ERR ,EAL ,"Failed to mmap buffer %u from %s\n" , i, hpi->hugedir);
Signature · 1 line
1.8.1.4
PATCH v7 3/19 eal: new eal option '--lcores' for cpu assignment
In reply to a message not in the archiveIt supports one new eal long option '--lcores' for EAL thread cpuset assignment.
The format pattern:
--lcores='lcores[@cpus]<,lcores[@cpus]>'
lcores, cpus could be a single digit/range or a group. '(' and ')' are necessary if it's a group.
If not supply '@cpus', the value of cpus uses the same as lcores.
e.g. '1,2@(5-7),(3-5)@(0,2),(0,6),7-8' means starting 9 EAL thread as below
lcore 0 runs on cpuset 0x41 (cpu 0,6)
lcore 1 runs on cpuset 0x2 (cpu 1)
lcore 2 runs on cpuset 0xe0 (cpu 5,6,7)
lcore 3,4,5 runs on cpuset 0x5 (cpu 0,2)
lcore 6 runs on cpuset 0x41 (cpu 0,6)
lcore 7 runs on cpuset 0x80 (cpu 7)
lcore 8 runs on cpuset 0x100 (cpu 8)
---
v5 changes:
add more comments for eal_parse_set
fix some typo
remove inline prefix from convert_to_cpuset() fix a bug introduced on v2 which broke case '(0,6)'
v2 changes:
add '<number>-<number>' support for EAL option '--lcores'
lib/librte_eal/common/eal_common_options.c | 304 ++++++++++++++++++++++++++++- lib/librte_eal/common/eal_options.h | 2 + lib/librte_eal/linuxapp/eal/Makefile | 1 + 3 files changed, 303 insertions(+), 4 deletions(-)
lib/librte_eal/common/eal_common_options.c +300 -4
@@ -45,6 +45,7 @@#include <rte_lcore.h> #include <rte_version.h> #include <rte_devargs.h> +#include <rte_memcpy.h> #include "eal_internal_cfg.h" #include "eal_options.h"
@@ -85,6 +86,7 @@ eal_long_options[] = { {OPT_XEN_DOM0, 0, 0, OPT_XEN_DOM0_NUM}, {OPT_CREATE_UIO_DEV, 1, NULL, OPT_CREATE_UIO_DEV_NUM}, {OPT_VFIO_INTR, 1, NULL, OPT_VFIO_INTR_NUM}, + {OPT_LCORES, 1, 0, OPT_LCORES_NUM}, {0, 0, 0, 0} };
@@ -255,9 +257,11 @@ eal_parse_corelist(const char *corelist)if (min ==RTE_MAX_LCORE ) min = idx;for (idx = min; idx <= max; idx++) { - cfg->lcore_role[idx] =ROLE_RTE ; - lcore_config[idx].core_index = count; - count++; +if (cfg->lcore_role[idx] !=ROLE_RTE ) { + cfg->lcore_role[idx] =ROLE_RTE ; + lcore_config[idx].core_index = count; + count++; + } } min =RTE_MAX_LCORE ; }else
@@ -292,6 +296,283 @@ eal_parse_master_lcore(const char *arg)return 0 ; } +/* +* Parse elem, the elem could be single number/range or '(' ')' group +* 1) A single number elem, it's just a simple digit. e.g. 9 +* 2) A single range elem, two digits with a '-' between. e.g. 2-6 +* 3) A group elem, combines multiple 1) or 2) with '( )'. e.g (0,2-4,6) +* Within group elem, '-' used for a range separator; +* ',' used for a single number. +*/ +static int +eal_parse_set (const char *input,uint16_t set[],unsigned num) +{ +unsigned idx; +const char *str = input; +char *end =NULL ; +unsigned min, max; + +memset (set,0 , num *sizeof (uint16_t )); + +while (isblank (*str)) + str++; + +/* only digit or left bracket is qualify for start point */ +if ((!isdigit (*str) && *str !='(' ) || *str =='\0' ) +return -1 ; + +/* process single number or single range of number */ +if (*str !='(' ) { + errno =0 ; + idx =strtoul (str, &end,10 ); +if (errno || end ==NULL || idx >= num) +return -1 ; +else { +while (isblank (*end)) + end++; + + min = idx; + max = idx; +if (*end =='-' ) { +/* process single <number>-<number> */ + end++; +while (isblank (*end)) + end++; +if (!isdigit (*end)) +return -1 ; + + errno =0 ; + idx =strtoul (end, &end,10 ); +if (errno || end ==NULL || idx >= num) +return -1 ; + max = idx; +while (isblank (*end)) + end++; +if (*end !=',' && *end !='\0' ) +return -1 ; + } + +if (*end !=',' && *end !='\0' && + *end !='@' ) +return -1 ; + +for (idx =RTE_MIN (min, max); + idx <=RTE_MAX (min, max); idx++) + set[idx] =1 ; + +return end - input; + } + } + +/* process set within bracket */ + str++; +while (isblank (*str)) + str++; +if (*str =='\0' ) +return -1 ; + + min =RTE_MAX_LCORE ; +do { + +/* go ahead to the first digit */ +while (isblank (*str)) + str++; +if (!isdigit (*str)) +return -1 ; + +/* get the digit value */ + errno =0 ; + idx =strtoul (str, &end,10 ); +if (errno || end ==NULL || idx >= num) +return -1 ; + +/* go ahead to separator '-',',' and ')' */ +while (isblank (*end)) + end++; +if (*end =='-' ) { +if (min ==RTE_MAX_LCORE ) + min = idx; +else /* avoid continuous '-' */ +return -1 ; + }else if ((*end ==',' ) || (*end ==')' )) { + max = idx; +if (min ==RTE_MAX_LCORE ) + min = idx; +for (idx =RTE_MIN (min, max); + idx <=RTE_MAX (min, max); idx++) + set[idx] =1 ; + + min =RTE_MAX_LCORE ; + }else +return -1 ; + + str = end +1 ; + }while (*end !='\0' && *end !=')' ); + +return str - input; +} + +/* convert from set array to cpuset bitmap */ +static int +convert_to_cpuset (rte_cpuset_t *cpusetp, +uint16_t *set,unsigned num) +{ +unsigned idx; + +CPU_ZERO (cpusetp); + +for (idx =0 ; idx < num; idx++) { +if (!set[idx]) +continue ; + +if (!lcore_config[idx].detected) { +RTE_LOG (ERR ,EAL ,"core %u " +"unavailable\n" , idx); +return -1 ; + } + +CPU_SET (idx, cpusetp); + } + +return 0 ; +} + +/* +* The format pattern: --lcores='lcores[@cpus]<,lcores[@cpus]>' +* lcores, cpus could be a single digit/range or a group. +* '(' and ')' are necessary if it's a group. +* If not supply '@cpus', the value of cpus uses the same as lcores. +* e.g. '1,2@(5-7),(3-5)@(0,2),(0,6),7-8' means start 9 EAL thread as below +* lcore 0 runs on cpuset 0x41 (cpu 0,6) +* lcore 1 runs on cpuset 0x2 (cpu 1) +* lcore 2 runs on cpuset 0xe0 (cpu 5,6,7) +* lcore 3,4,5 runs on cpuset 0x5 (cpu 0,2) +* lcore 6 runs on cpuset 0x41 (cpu 0,6) +* lcore 7 runs on cpuset 0x80 (cpu 7) +* lcore 8 runs on cpuset 0x100 (cpu 8) +*/ +static int +eal_parse_lcores (const char *lcores) +{ +struct rte_config *cfg =rte_eal_get_configuration (); +static uint16_t set[RTE_MAX_LCORE ]; +unsigned idx =0 ; +int i; +unsigned count =0 ; +const char *lcore_start =NULL ; +const char *end =NULL ; +int offset; +rte_cpuset_t cpuset; +int lflags =0 ; +int ret =-1 ; + +if (lcores ==NULL ) +return -1 ; + +/* Remove all blank characters ahead and after */ +while (isblank (*lcores)) + lcores++; + i =strnlen (lcores,sysconf (_SC_ARG_MAX)); +while ((i >0 ) &&isblank (lcores[i -1 ])) + i--; + +CPU_ZERO (&cpuset); + +/* Reset lcore config */ +for (idx =0 ; idx <RTE_MAX_LCORE ; idx++) { + cfg->lcore_role[idx] =ROLE_OFF ; + lcore_config[idx].core_index =-1 ; +CPU_ZERO (&lcore_config[idx].cpuset); + } + +/* Get list of cores */ +do { +while (isblank (*lcores)) + lcores++; +if (*lcores =='\0' ) + goto err; + +/* record lcore_set start point */ + lcore_start = lcores; + +/* go across a complete bracket */ +if (*lcore_start =='(' ) { + lcores +=strcspn (lcores,")" ); +if (*lcores++ =='\0' ) + goto err; + } + +/* scan the separator '@', ','(next) or '\0'(finish) */ + lcores +=strcspn (lcores,"@," ); + +if (*lcores =='@' ) { +/* explict assign cpu_set */ + offset =eal_parse_set (lcores +1 , set,RTE_DIM (set)); +if (offset <0 ) + goto err; + +/* prepare cpu_set and update the end cursor */ +if (0 >convert_to_cpuset (&cpuset, + set,RTE_DIM (set))) + goto err; + end = lcores +1 + offset; + }else {/* ',' or '\0' */ +/* haven't given cpu_set, current loop done */ + end = lcores; + +/* go back to check <number>-<number> */ + offset =strcspn (lcore_start,"(-" ); +if (offset < (end - lcore_start) && + *(lcore_start + offset) !='(' ) + lflags =1 ; + } + +if (*end !=',' && *end !='\0' ) + goto err; + +/* parse lcore_set from start point */ +if (0 >eal_parse_set (lcore_start, set,RTE_DIM (set))) + goto err; + +/* without '@', by default using lcore_set as cpu_set */ +if (*lcores !='@' && +0 >convert_to_cpuset (&cpuset, set,RTE_DIM (set))) + goto err; + +/* start to update lcore_set */ +for (idx =0 ; idx <RTE_MAX_LCORE ; idx++) { +if (!set[idx]) +continue ; + +if (cfg->lcore_role[idx] !=ROLE_RTE ) { + lcore_config[idx].core_index = count; + cfg->lcore_role[idx] =ROLE_RTE ; + count++; + } + +if (lflags) { +CPU_ZERO (&cpuset); +CPU_SET (idx, &cpuset); + } +rte_memcpy (&lcore_config[idx].cpuset, &cpuset, +sizeof (rte_cpuset_t)); + } + + lcores = end +1 ; + }while (*end !='\0' ); + +if (count ==0 ) + goto err; + + cfg->lcore_count = count; + lcores_parsed =1 ; + ret =0 ; + +err: + +return ret; +} +static int eal_parse_syslog (const char *facility,struct internal_config *conf) {
@@ -492,6 +773,13 @@ eal_parse_common_option(int opt, const char *optarg, conf->log_level = log;break ; } +case OPT_LCORES_NUM : +if (eal_parse_lcores (optarg) <0 ) { +RTE_LOG (ERR ,EAL ,"invalid parameter for --" +OPT_LCORES "\n" ); +return -1 ; + } +break ;/* don't know what to do, leave this to caller */ default :
@@ -530,7 +818,7 @@ eal_check_common_options(struct internal_config *internal_cfg)if (!lcores_parsed) {RTE_LOG (ERR ,EAL ,"CPU cores must be enabled with options " -"-c or -l\n" ); +"-c, -l or --lcores\n" );return -1 ; }if (cfg->lcore_role[cfg->master_lcore] !=ROLE_RTE ) {
@@ -586,6 +874,14 @@ eal_common_usage(void)" The argument format is <c1>[-c2][,c3[-c4],...]\n" " where c1, c2, etc are core indexes between 0 and %d\n" " --" OPT_MASTER_LCORE " ID: Core ID that is used as master\n" +" --" OPT_LCORES " MAP: maps between lcore_set to phys_cpu_set\n" +" The argument format is\n" +" 'lcores[@cpus]<,lcores[@cpus],...>'\n" +" lcores and cpus list are grouped by '(' and ')'\n" +" Within the group, '-' is used for range separator,\n" +" ',' is used for single number separator.\n" +" '( )' can be omitted for single element group, '@' \n" +" can be omitted if cpus and lcores has the same value\n" " -n NUM : Number of memory channels\n" " -v : Display version information on startup\n" " -m MB : memory to allocate (see also --" OPT_SOCKET_MEM ")\n"
lib/librte_eal/common/eal_options.h +2 -0
@@ -77,6 +77,8 @@ enum {OPT_CREATE_UIO_DEV_NUM , #define OPT_VFIO_INTR "vfio-intr"OPT_VFIO_INTR_NUM , +#define OPT_LCORES "lcores" +OPT_LCORES_NUM , OPT_LONG_MAX_NUM };
lib/librte_eal/linuxapp/eal/Makefile +1 -0
@@ -99,6 +99,7 @@ CFLAGS_eal_hugepage_info.o := -D_GNU_SOURCE CFLAGS_eal_pci.o := -D_GNU_SOURCE CFLAGS_eal_pci_vfio.o := -D_GNU_SOURCE CFLAGS_eal_common_whitelist.o := -D_GNU_SOURCE +CFLAGS_eal_common_options.o := -D_GNU_SOURCE # workaround for a gcc bug with noreturn attribute # http://gcc.gnu.org/bugzilla/show_bug.cgi?id=12603
Signature · 1 line
1.8.1.4
PATCH v7 4/19 eal: fix wrong strnlen() return value in 32bit icc
In reply to a message not in the archiveThe problem is that strnlen() here may return invalid value with 32bit icc. (actually it returns it’s second parameter,e.g: sysconf(_SC_ARG_MAX)).
It starts to manifest hwen max_len parameter is > 2M and using icc –m32 –O2 (or above).
---
v7 changes:
rollback to use strnlen
v5 changes:
using strlen instead of strnlen.
lib/librte_eal/common/eal_common_options.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-)
lib/librte_eal/common/eal_common_options.c +4 -3
@@ -52,6 +52,7 @@#include "eal_filesystem.h" #define BITS_PER_HEX 4 +#define EAL_ARG_MAX 4096const char eal_short_options[] =
@@ -167,7 +168,7 @@ eal_parse_coremask(const char *coremask)if (coremask[0 ] =='0' && ((coremask[1 ] =='x' ) || (coremask[1 ] =='X' ))) coremask +=2 ; - i =strnlen (coremask,PATH_MAX ); + i =strnlen (coremask,EAL_ARG_MAX );while ((i >0 ) &&isblank (coremask[i -1 ])) i--;if (i ==0 )
@@ -227,7 +228,7 @@ eal_parse_corelist(const char *corelist)/* Remove all blank characters ahead and after */ while (isblank (*corelist)) corelist++; - i =strnlen (corelist,sysconf (_SC_ARG_MAX)); + i =strnlen (corelist,EAL_ARG_MAX );while ((i >0 ) &&isblank (corelist[i -1 ])) i--;
@@ -472,7 +473,7 @@ eal_parse_lcores(const char *lcores)/* Remove all blank characters ahead and after */ while (isblank (*lcores)) lcores++; - i =strnlen (lcores,sysconf (_SC_ARG_MAX)); + i =strnlen (lcores,EAL_ARG_MAX );while ((i >0 ) &&isblank (lcores[i -1 ])) i--;
Signature · 1 line
1.8.1.4
A message that is not in the archive (sent off-list or not yet received): 1423970145-31985-5-git-send-email-cunming.liang-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org
Re: [PATCH v7 04/19] eal: fix wrong strnlen() return value in 32bit icc
Hi,
Quoted 6 lines · Cunming Liang
The problem is that
strnlen()here may return invalid value with 32bit icc. (actually it returns it’s second parameter,e.g:sysconf(_SC_ARG_MAX)).
It starts to manifest hwenmax_lenparameter is > 2M and using icc –m32 –O2 (or above).Suggested-by Konstantin Ananyev <[email protected]>Signed-off-by Cunming Liang <[email protected]>
Sorry but I don't think using strnlen() is appropriate here. See
http://dpdk.org/ml/archives/dev/2015-February/013309.html
Regards,
Olivier
A message that is not in the archive (sent off-list or not yet received): [email protected]
Re: [PATCH v7 04/19] eal: fix wrong strnlen() return value in 32bit icc
Quoted 20 lines
-----Original Message-----
From: Olivier MATZ [mailto:[email protected]]
Sent: Monday, February 16, 2015 10:52 PM
To: Liang, Cunming; [email protected]
Cc: Ananyev, Konstantin; [email protected]
Subject: Re: [PATCH v7 04/19] eal: fix wrongstrnlen()return value in 32bit iccHi,
Quoted 3 lines · Cunming Liang
The problem is that
strnlen()here may return invalid value with 32bit icc. (actually it returns it’s second parameter,e.g:sysconf(_SC_ARG_MAX)). It starts to manifest hwenmax_lenparameter is > 2M and using icc –m32 –O2(or above).
Quoted 3 lines
Suggested-by Konstantin Ananyev <[email protected]>Signed-off-by Cunming Liang <[email protected]>
Quoted 8 lines
Sorry but I don't think using
strnlen()is appropriate here. See
http://dpdk.org/ml/archives/dev/2015-February/013309.htmlI still don't agree that we should use
strnlen(coremask, ARG_MAX).The API of
eal_parse_coremask()requires that a valid string is passed as an argument, sostrlen()is perfectly fine. It's up to the caller to ensure that the string is valid.
[LCM] To me, personally I think either strlen() or strnlen(str, EAL_ARG_MAX) is ok.
Neil's point is that 'eal_parse_common_option()' extern as a EAL global function, itself should avoid the dirty input. That's for security programming. As strlen() intended to be used only to calculate the size of incoming untrusted data in a buffer of known size.
Your point is strlen() is enough as it only be used in EAL, and so far all input comes from optarg which is trusted data from getopt_long(). Add Thomas in cc list, I'll submit a v8 to make sure in both case there's patch series ready.
Quoted 5 lines
Using
strnlen(coremask, ARG_MAX)ineal_parse_coremask()with an
arbitrary length does not protect from having a segfault in case the
string is invalid and the caller's buffer length is <ARG_MAX.
[LCM] I'm afraid not getting your point here. It causes segfault only if the input string is NULL, doesn't it ?
As it already check the case, so using strnlen do protect against the unterminated string.
Quoted 5 lines
This would still be true even if
eal_parse_coremask()is public.Regards,
Olivier
PATCH v7 5/19 eal: add public function parsing socket_id from cpuid
In reply to a message not in the archiveIt defines eal_cpu_socket_id() which exposing the origin private cpu_socket_id(). The function is only used inside EAL. It returns socket_id of the specified cpu_id.
---
v7 changes:
reword comments
v5 changes:
expose cpu_socket_id as eal_cpu_socket_id for linuxapp eal_cpuset_socket_id() remove static inline and move to c file
lib/librte_eal/bsdapp/eal/eal_lcore.c | 7 +++++++ lib/librte_eal/common/eal_thread.h | 11 +++++++++++ lib/librte_eal/linuxapp/eal/eal_lcore.c | 7 ++++--- 3 files changed, 22 insertions(+), 3 deletions(-)
lib/librte_eal/bsdapp/eal/eal_lcore.c +7 -0
@@ -41,6 +41,7 @@#include <rte_debug.h> #include "eal_private.h" +#include "eal_thread.h" /* No topology information available on FreeBSD including NUMA info */ #define cpu_core_id (X ) 0
@@ -112,3 +113,9 @@ rte_eal_cpu_init(void)return 0 ; } + +unsigned +eal_cpu_socket_id (__rte_unused unsigned cpu_id) +{ +return cpu_socket_id (cpu_id); +}
lib/librte_eal/common/eal_thread.h +11 -0
@@ -50,4 +50,15 @@ __attribute__((noreturn)) void *eal_thread_loop(void *arg);*/ void eal_thread_init_master (unsigned lcore_id); +/** +* Get the NUMA socket id from cpu id. +* This function is private to EAL. +* +* @param cpu_id +* The logical process id. +* @return +* socket_id or SOCKET_ID_ANY +*/ +unsigned eal_cpu_socket_id (unsigned cpu_id); +#endif /* EAL_THREAD_H */
lib/librte_eal/linuxapp/eal/eal_lcore.c +4 -3
@@ -45,6 +45,7 @@#include "eal_private.h" #include "eal_filesystem.h" +#include "eal_thread.h" #define SYS_CPU_DIR "/sys/devices/system/cpu/cpu%u"#define CORE_ID_FILE "topology/core_id"
@@ -71,8 +72,8 @@ cpu_detected(unsigned lcore_id)* Note: physical package id != NUMA node, but we use it as a * fallback for kernels which don't create a nodeY link */ -static unsigned -cpu_socket_id (unsigned lcore_id) +unsigned +eal_cpu_socket_id (unsigned lcore_id) {const char node_prefix[] ="node" ;const size_t prefix_len =sizeof (node_prefix) -1 ;
@@ -174,7 +175,7 @@ rte_eal_cpu_init(void)/* By default, each detected core is enabled */ config->lcore_role[lcore_id] =ROLE_RTE ; lcore_config[lcore_id].core_id =cpu_core_id (lcore_id); - lcore_config[lcore_id].socket_id =cpu_socket_id (lcore_id); + lcore_config[lcore_id].socket_id =eal_cpu_socket_id (lcore_id); if (lcore_config[lcore_id].socket_id >= RTE_MAX_NUMA_NODES)#ifdef RTE_EAL_ALLOW_INV_SOCKET_ID lcore_config[lcore_id].socket_id =0 ;
Signature · 1 line
1.8.1.4
PATCH v7 6/19 eal: new TLS definition and API declaration
In reply to a message not in the archive1. add two TLS *_socket_id* and *_cpuset*
2. add two internal API, eal_cpu_socket_id/eal_thread_dump_affinity
3. add two public API, rte_thread_set/get_affinity
4. update EAL version map for EAL public API
---
v7 changes:
update version map for EAL public API and reword comments
v5 changes:
add comments for RTE_CPU_AFFINITY_STR_LEN
update comments for eal_thread_dump_affinity()
return void for rte_thread_get_affinity()
move rte_socket_id() change to another patch
lib/librte_eal/bsdapp/eal/eal_thread.c | 2 ++ lib/librte_eal/bsdapp/eal/rte_eal_version.map | 2 ++ lib/librte_eal/common/eal_thread.h | 36 +++++++++++++++++++++++++ lib/librte_eal/common/include/rte_lcore.h | 26 +++++++++++++++++- lib/librte_eal/linuxapp/eal/eal_thread.c | 2 ++ lib/librte_eal/linuxapp/eal/rte_eal_version.map | 2 ++ 6 files changed, 69 insertions(+), 1 deletion(-)
lib/librte_eal/bsdapp/eal/eal_thread.c +2 -0
@@ -56,6 +56,8 @@#include "eal_thread.h" RTE_DEFINE_PER_LCORE (unsigned, _lcore_id); +RTE_DEFINE_PER_LCORE (unsigned, _socket_id); +RTE_DEFINE_PER_LCORE (rte_cpuset_t, _cpuset);/* * Send a message to a slave lcore identified by slave_id to call a
lib/librte_eal/bsdapp/eal/rte_eal_version.map +2 -0
@@ -82,6 +82,8 @@ DPDK_2.0 { rte_snprintf; rte_strerror; rte_strsplit; + rte_thread_get_affinity; + rte_thread_set_affinity; rte_vlog; rte_xen_dom0_memory_attach; rte_xen_dom0_memory_init;
lib/librte_eal/common/eal_thread.h +36 -0
@@ -34,6 +34,8 @@#ifndef EAL_THREAD_H #define EAL_THREAD_H +#include <rte_lcore.h> +/** * basic loop of thread, called for each thread by eal_init(). *
@@ -61,4 +63,38 @@ void eal_thread_init_master(unsigned lcore_id);*/ unsigned eal_cpu_socket_id (unsigned cpu_id); +/** +* Get the NUMA socket id from cpuset. +* This function is private to EAL. +* +* @param cpusetp +* The point to a valid cpu set. +* @return +* socket_id or SOCKET_ID_ANY +*/ +int eal_cpuset_socket_id (rte_cpuset_t *cpusetp); + +/** +* Default buffer size to use with eal_thread_dump_affinity() +*/ +#define RTE_CPU_AFFINITY_STR_LEN 256 + +/** +* Dump the current pthread cpuset. +* This function is private to EAL. +* +* Note: +* If the dump size is greater than the size of given buffer, +* the string will be truncated and with '\0' at the end. +* +* @param str +* The string buffer the cpuset will dump to. +* @param size +* The string buffer size. +* @return +* 0 for success, -1 if truncation happens. +*/ +int +eal_thread_dump_affinity (char *str,unsigned size); +#endif /* EAL_THREAD_H */
lib/librte_eal/common/include/rte_lcore.h +25 -1
@@ -80,7 +80,9 @@ struct lcore_config {*/ extern struct lcore_config lcore_config[RTE_MAX_LCORE ]; -RTE_DECLARE_PER_LCORE (unsigned, _lcore_id);/**< Per core "core id". */ +RTE_DECLARE_PER_LCORE (unsigned, _lcore_id);/**< Per thread "lcore id". */ +RTE_DECLARE_PER_LCORE (unsigned, _socket_id);/**< Per thread "socket id". */ +RTE_DECLARE_PER_LCORE (rte_cpuset_t, _cpuset);/**< Per thread "cpuset". */ /** * Return the ID of the execution unit we are running on.
@@ -229,6 +231,28 @@ rte_get_next_lcore(unsigned i, int skip_master, int wrap) i<RTE_MAX_LCORE ; \ i = rte_get_next_lcore(i, 1, 0)) +/** +* Set core affinity of the current thread. +* Support both EAL and none-EAL thread and update TLS. +* +* @param cpusetp +* Point to cpu_set_t for setting current thread affinity. +* @return +* On success, return 0; otherwise return -1; +*/ +int rte_thread_set_affinity (rte_cpuset_t *cpusetp); + +/** +* Get core affinity of the current thread. +* +* @param cpusetp +* Point to cpu_set_t for getting current thread cpu affinity. +* It presumes input is not NULL, otherwise it causes panic. +* +*/ +void rte_thread_get_affinity (rte_cpuset_t *cpusetp); + + #ifdef __cplusplus }#endif
lib/librte_eal/linuxapp/eal/eal_thread.c +2 -0
@@ -56,6 +56,8 @@#include "eal_thread.h" RTE_DEFINE_PER_LCORE (unsigned, _lcore_id); +RTE_DEFINE_PER_LCORE (unsigned, _socket_id); +RTE_DEFINE_PER_LCORE (rte_cpuset_t, _cpuset);/* * Send a message to a slave lcore identified by slave_id to call a
lib/librte_eal/linuxapp/eal/rte_eal_version.map +2 -0
@@ -82,6 +82,8 @@ DPDK_2.0 { rte_snprintf; rte_strerror; rte_strsplit; + rte_thread_get_affinity; + rte_thread_set_affinity; rte_vlog; rte_xen_dom0_memory_attach; rte_xen_dom0_memory_init;
Signature · 1 line
1.8.1.4
PATCH v7 7/19 eal: add eal_common_thread.c for common thread API
In reply to a message not in the archiveThe API works for both EAL thread and none EAL thread. When calling rte_thread_set_affinity, the *_socket_id* and *_cpuset* of calling thread will be updated if the thread successful set the cpu affinity.
---
v5 changes:
refine code of rte_thread_set_affinity() change rte_thread_get_affinity() return to void
lib/librte_eal/bsdapp/eal/Makefile | 1 + lib/librte_eal/common/eal_common_thread.c | 150 ++++++++++++++++++++++++++++++ lib/librte_eal/linuxapp/eal/Makefile | 2 + 3 files changed, 153 insertions(+) create mode 100644 lib/librte_eal/common/eal_common_thread.c
lib/librte_eal/bsdapp/eal/Makefile +1 -0
@@ -77,6 +77,7 @@ SRCS-$(CONFIG_RTE_LIBRTE_EAL_BSDAPP) += eal_common_hexdump.c SRCS-$(CONFIG_RTE_LIBRTE_EAL_BSDAPP) += eal_common_devargs.c SRCS-$(CONFIG_RTE_LIBRTE_EAL_BSDAPP) += eal_common_dev.c SRCS-$(CONFIG_RTE_LIBRTE_EAL_BSDAPP) += eal_common_options.c +SRCS-$(CONFIG_RTE_LIBRTE_EAL_BSDAPP) += eal_common_thread.c CFLAGS_eal.o := -D_GNU_SOURCE #CFLAGS_eal_thread.o := -D_GNU_SOURCE
lib/librte_eal/common/eal_common_thread.c new file +150 -0
150 lines not on this page · raw message
lib/librte_eal/linuxapp/eal/Makefile +2 -0
@@ -89,6 +89,7 @@ SRCS-$(CONFIG_RTE_LIBRTE_EAL_LINUXAPP) += eal_common_hexdump.c SRCS-$(CONFIG_RTE_LIBRTE_EAL_LINUXAPP) += eal_common_devargs.c SRCS-$(CONFIG_RTE_LIBRTE_EAL_LINUXAPP) += eal_common_dev.c SRCS-$(CONFIG_RTE_LIBRTE_EAL_LINUXAPP) += eal_common_options.c +SRCS-$(CONFIG_RTE_LIBRTE_EAL_LINUXAPP) += eal_common_thread.c CFLAGS_eal.o := -D_GNU_SOURCE CFLAGS_eal_lcore.o := -D_GNU_SOURCE
@@ -100,6 +101,7 @@ CFLAGS_eal_pci.o := -D_GNU_SOURCE CFLAGS_eal_pci_vfio.o := -D_GNU_SOURCE CFLAGS_eal_common_whitelist.o := -D_GNU_SOURCE CFLAGS_eal_common_options.o := -D_GNU_SOURCE +CFLAGS_eal_common_thread.o := -D_GNU_SOURCE # workaround for a gcc bug with noreturn attribute # http://gcc.gnu.org/bugzilla/show_bug.cgi?id=12603
Signature · 1 line
1.8.1.4
PATCH v7 8/19 eal: standardize init sequence between linux and bsd
In reply to a message not in the archive--- lib/librte_eal/bsdapp/eal/eal.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
lib/librte_eal/bsdapp/eal/eal.c +2 -2
@@ -509,6 +509,8 @@ rte_eal_init(int argc, char **argv)rte_eal_mcfg_complete (); +eal_thread_init_master (rte_config.master_lcore); +if (rte_eal_dev_init () <0 )rte_panic ("Cannot init pmd devices\n" );
@@ -532,8 +534,6 @@ rte_eal_init(int argc, char **argv)rte_panic ("Cannot create thread\n" ); } -eal_thread_init_master (rte_config.master_lcore); -/* * Launch a dummy function on all slave lcores, so that master lcore * knows they are all ready when this function returns.
Signature · 1 line
1.8.1.4
PATCH v7 9/19 eal: add rte_gettid() to acquire unique system tid
In reply to a message not in the archiveThe rte_gettid() wraps the linux and freebsd syscall gettid(). It provides a persistent unique thread id for the calling thread. It will save the unique id in TLS on the first time.
--- lib/librte_eal/bsdapp/eal/eal_thread.c | 9 +++++++++ lib/librte_eal/common/include/rte_eal.h | 27 +++++++++++++++++++++++++++ lib/librte_eal/linuxapp/eal/eal_thread.c | 7 +++++++ 3 files changed, 43 insertions(+)
lib/librte_eal/bsdapp/eal/eal_thread.c +9 -0
@@ -39,6 +39,7 @@#include <sched.h> #include <pthread_np.h> #include <sys/queue.h> +#include <sys/thr.h> #include <rte_debug.h> #include <rte_atomic.h>
@@ -233,3 +234,11 @@ eal_thread_loop(__attribute__((unused)) void *arg)/* pthread_exit(NULL); */ /* return NULL; */ } + +/* require calling thread tid by gettid() */ +int rte_sys_gettid (void ) +{ +long lwpid; +thr_self (&lwpid); +return (int )lwpid; +}
lib/librte_eal/common/include/rte_eal.h +27 -0
@@ -41,6 +41,9 @@*/ #include <stdint.h> +#include <sched.h> + +#include <rte_per_lcore.h> #ifdef __cplusplusextern "C" {
@@ -262,6 +265,30 @@ rte_set_application_usage_hook( rte_usage_hook_t usage_func );*/ int rte_eal_has_hugepages (void ); +/** +* A wrap API for syscall gettid. +* +* @return +* On success, returns the thread ID of calling process. +* It always successful. +*/ +int rte_sys_gettid (void ); + +/** +* Get system unique thread id. +* +* @return +* On success, returns the thread ID of calling process. +* It always successful. +*/ +static inline int rte_gettid (void ) +{ + static RTE_DEFINE_PER_LCORE(int, _thread_id) = -1; +if (RTE_PER_LCORE (_thread_id) ==-1 ) +RTE_PER_LCORE (_thread_id) =rte_sys_gettid (); +return RTE_PER_LCORE (_thread_id); +} + #ifdef __cplusplus }#endif
lib/librte_eal/linuxapp/eal/eal_thread.c +7 -0
@@ -39,6 +39,7 @@#include <pthread.h> #include <sched.h> #include <sys/queue.h> +#include <sys/syscall.h> #include <rte_debug.h> #include <rte_atomic.h>
@@ -233,3 +234,9 @@ eal_thread_loop(__attribute__((unused)) void *arg)/* pthread_exit(NULL); */ /* return NULL; */ } + +/* require calling thread tid by gettid() */ +int rte_sys_gettid (void ) +{ +return (int )syscall (SYS_gettid); +}
Signature · 1 line
1.8.1.4
PATCH v7 10/19 eal: apply affinity of EAL thread by assigned cpuset
In reply to a message not in the archiveEAL threads use assigned cpuset to set core affinity during startup. It keeps 1:1 mapping, if no '--lcores' option is used.
---
v5 changes:
add return check for dump_affinity
call rte_thread_set_affinity() directly during EAL thread set
lib/librte_eal/bsdapp/eal/eal.c | 10 +++-- lib/librte_eal/bsdapp/eal/eal_thread.c | 64 ++++++------------------------ lib/librte_eal/common/include/rte_lcore.h | 2 +- lib/librte_eal/linuxapp/eal/eal.c | 8 +++- lib/librte_eal/linuxapp/eal/eal_thread.c | 66 ++++++------------------------- 5 files changed, 37 insertions(+), 113 deletions(-)
lib/librte_eal/bsdapp/eal/eal.c +7 -3
@@ -432,6 +432,7 @@ rte_eal_init(int argc, char **argv)int i, fctret, ret;pthread_t thread_id;static rte_atomic32_t run_once =RTE_ATOMIC32_INIT (0 ); +char cpuset[RTE_CPU_AFFINITY_STR_LEN ];if (!rte_atomic32_test_and_set (&run_once))return -1 ;
@@ -502,15 +503,18 @@ rte_eal_init(int argc, char **argv)if (rte_eal_pci_init () <0 )rte_panic ("Cannot init PCI\n" ); -RTE_LOG (DEBUG ,EAL ,"Master core %u is ready (tid=%p)\n" , - rte_config.master_lcore, thread_id); -eal_check_mem_on_local_socket ();rte_eal_mcfg_complete ();eal_thread_init_master (rte_config.master_lcore); + ret =eal_thread_dump_affinity (cpuset,RTE_CPU_AFFINITY_STR_LEN ); + +RTE_LOG (DEBUG ,EAL ,"Master lcore %u is ready (tid=%p;cpuset=[%s%s])\n" , + rte_config.master_lcore, thread_id, cpuset, + ret ==0 ?"" :"..." ); +if (rte_eal_dev_init () <0 )rte_panic ("Cannot init pmd devices\n" );
lib/librte_eal/bsdapp/eal/eal_thread.c +11 -53
90 lines not on this page · raw message
lib/librte_eal/common/include/rte_lcore.h +1 -1
@@ -148,7 +148,7 @@ rte_lcore_index(int lcore_id)static inline unsigned rte_socket_id (void ) { -return lcore_config[rte_lcore_id ()].socket_id; +return RTE_PER_LCORE (_socket_id); }/**
lib/librte_eal/linuxapp/eal/eal.c +6 -2
@@ -702,6 +702,7 @@ rte_eal_init(int argc, char **argv)static rte_atomic32_t run_once =RTE_ATOMIC32_INIT (0 );struct shared_driver *solib =NULL ;const char *logid; +char cpuset[RTE_CPU_AFFINITY_STR_LEN ];if (!rte_atomic32_test_and_set (&run_once))return -1 ;
@@ -802,8 +803,11 @@ rte_eal_init(int argc, char **argv)eal_thread_init_master (rte_config.master_lcore); -RTE_LOG (DEBUG ,EAL ,"Master core %u is ready (tid=%x)\n" , - rte_config.master_lcore, (int )thread_id); + ret =eal_thread_dump_affinity (cpuset,RTE_CPU_AFFINITY_STR_LEN ); + +RTE_LOG (DEBUG ,EAL ,"Master lcore %u is ready (tid=%x;cpuset=[%s%s])\n" , + rte_config.master_lcore, (int )thread_id, cpuset, + ret ==0 ?"" :"..." );if (rte_eal_dev_init () <0 )rte_panic ("Cannot init pmd devices\n" );
lib/librte_eal/linuxapp/eal/eal_thread.c +12 -54
95 lines not on this page · raw message
Signature · 1 line
1.8.1.4
PATCH v7 11/19 enic: fix re-define freebsd compile complain
In reply to a message not in the archiveSome macro already been defined by freebsd 'sys/param.h'.
---
v5 changes:
rename the redefined MACRO instead of undefine them
lib/librte_pmd_enic/enic.h | 4 ++-- lib/librte_pmd_enic/enic_compat.h | 2 +- lib/librte_pmd_enic/vnic/vnic_dev.c | 6 +++--- 3 files changed, 6 insertions(+), 6 deletions(-)
lib/librte_pmd_enic/enic.h +2 -2
@@ -66,9 +66,9 @@#define ENIC_CALC_IP_CKSUM 1#define ENIC_CALC_TCP_UDP_CKSUM 2#define ENIC_MAX_MTU 9000 -#define PAGE_SIZE 4096 +#define ENIC_PAGE_SIZE 4096#define PAGE_ROUND_UP (x) \ - ((((unsigned long)(x)) + PAGE_SIZE-1) & (~(PAGE_SIZE-1))) + ((((unsigned long)(x)) + ENIC_PAGE_SIZE-1) & (~(ENIC_PAGE_SIZE-1)))#define ENICPMD_VFIO_PATH "/dev/vfio/vfio"/*#define ENIC_DESC_COUNT_MAKE_ODD (x) do{if ((~(x)) & 1) { (x)--; } }while(0)*/
lib/librte_pmd_enic/enic_compat.h +1 -1
@@ -67,7 +67,7 @@ #define pr_warn(y, args...) dev_warning(0, y, ##args)#define BUG () pr_err("BUG at %s:%d", __func__, __LINE__) -#define ALIGN (x, a) __ALIGN_MASK(x, (typeof(x))(a)-1) +#define VNIC_ALIGN (x, a) __ALIGN_MASK(x, (typeof(x))(a)-1)#define __ALIGN_MASK (x, mask) (((x)+(mask))&~(mask))#define udelay usleep#define DIV_ROUND_UP (n, d) (((n) + (d) - 1) / (d))
lib/librte_pmd_enic/vnic/vnic_dev.c +3 -3
@@ -242,9 +242,9 @@ unsigned int vnic_dev_desc_ring_size(struct vnic_dev_ring *ring,if (desc_count ==0 ) desc_count =4096 ; - ring->desc_count =ALIGN (desc_count, count_align); + ring->desc_count =VNIC_ALIGN (desc_count, count_align); - ring->desc_size =ALIGN (desc_size, desc_align); + ring->desc_size =VNIC_ALIGN (desc_size, desc_align); ring->size = ring->desc_count * ring->desc_size; ring->size_unaligned = ring->size + ring->base_align;
@@ -294,7 +294,7 @@ int vnic_dev_alloc_desc_ring(__attribute__((unused)) struct vnic_dev *vdev, ring->base_addr_unaligned = (dma_addr_t )rz->phys_addr; - ring->base_addr =ALIGN (ring->base_addr_unaligned, + ring->base_addr =VNIC_ALIGN (ring->base_addr_unaligned, ring->base_align); ring->descs = (u8 *)ring->descs_unaligned + (ring->base_addr - ring->base_addr_unaligned);
Signature · 1 line
1.8.1.4
PATCH v7 12/19 malloc: fix the issue of SOCKET_ID_ANY
In reply to a message not in the archiveAdd check for rte_socket_id(), avoid get unexpected return like (-1).
By using rte_malloc_socket(), socket id is assigned by socket_arg.
If socket_arg set to SOCKET_ID_ANY, it expects to use the socket id to which the current cores belongs. As the thread may affinity on a cpuset, the cores in the cpuset may belongs to different NUMA nodes. The value of _socket_id probably be SOCKET_ID_ANY(-1), the case is not expected in origin malloc_get_numa_socket().
---
v7 changes:
reword comments
lib/librte_malloc/malloc_heap.h | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)
lib/librte_malloc/malloc_heap.h +6 -1
@@ -44,7 +44,12 @@ extern "C" {static inline unsigned malloc_get_numa_socket (void ) { -return rte_socket_id (); +unsigned socket_id =rte_socket_id (); + +if (socket_id == (unsigned )SOCKET_ID_ANY ) +return 0 ; + +return socket_id; } void *
Signature · 1 line
1.8.1.4
PATCH v7 13/19 log: fix the gap to support non-EAL thread
In reply to a message not in the archiveFor those non-EAL thread, *_lcore_id* is invalid and probably larger than RTE_MAX_LCORE. The patch adds the check and allows only EAL thread using EAL per thread log level and log type. Others shares the global log level.
--- lib/librte_eal/common/eal_common_log.c | 17 +++++++++++++++-- lib/librte_eal/common/include/rte_log.h | 5 +++++ 2 files changed, 20 insertions(+), 2 deletions(-)
lib/librte_eal/common/eal_common_log.c +15 -2
@@ -193,11 +193,20 @@ rte_set_log_type(uint32_t type, int enable) rte_logs.type &= (~type); } +/* Get global log type */ +uint32_t +rte_get_log_type (void ) +{ +return rte_logs.type; +} +/* get the current loglevel for the message beeing processed */ int rte_log_cur_msg_loglevel (void ) {unsigned lcore_id; lcore_id =rte_lcore_id (); +if (lcore_id >=RTE_MAX_LCORE ) +return rte_get_log_level ();return log_cur_msg[lcore_id].loglevel; }
@@ -206,6 +215,8 @@ int rte_log_cur_msg_logtype(void) {unsigned lcore_id; lcore_id =rte_lcore_id (); +if (lcore_id >=RTE_MAX_LCORE ) +return rte_get_log_type ();return log_cur_msg[lcore_id].logtype; }
@@ -265,8 +276,10 @@ rte_vlog(__attribute__((unused)) uint32_t level,/* save loglevel and logtype in a global per-lcore variable */ lcore_id =rte_lcore_id (); - log_cur_msg[lcore_id].loglevel = level; - log_cur_msg[lcore_id].logtype = logtype; +if (lcore_id <RTE_MAX_LCORE ) { + log_cur_msg[lcore_id].loglevel = level; + log_cur_msg[lcore_id].logtype = logtype; + } ret =vfprintf (f, format, ap);fflush (f);
lib/librte_eal/common/include/rte_log.h +5 -0
@@ -144,6 +144,11 @@ uint32_t rte_get_log_level(void);void rte_set_log_type (uint32_t type,int enable);/** +* Get the global log type. +*/ +uint32_t rte_get_log_type (void ); + +/** * Get the current loglevel for the message being processed. * * Before calling the user-defined stream for logging, the log
Signature · 1 line
1.8.1.4
PATCH v7 14/19 eal: set _lcore_id and _socket_id to (-1) by default
In reply to a message not in the archiveFor those none EAL thread, *_lcore_id* shall always be LCORE_ID_ANY. The libraries using *_lcore_id* as index need to take care. *_socket_id* always be SOCKET_ID_ANY unitl the thread changes the affinity by rte_thread_set_affinity()
---
v5 changes:
define LCORE_ID_ANY as UINT32_MAX
lib/librte_eal/bsdapp/eal/eal_thread.c | 4 ++-- lib/librte_eal/common/include/rte_lcore.h | 4 ++-- lib/librte_eal/linuxapp/eal/eal_thread.c | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-)
lib/librte_eal/bsdapp/eal/eal_thread.c +2 -2
@@ -56,8 +56,8 @@#include "eal_private.h" #include "eal_thread.h" -RTE_DEFINE_PER_LCORE (unsigned, _lcore_id); -RTE_DEFINE_PER_LCORE (unsigned, _socket_id); +RTE_DEFINE_PER_LCORE (unsigned, _lcore_id) =LCORE_ID_ANY ; +RTE_DEFINE_PER_LCORE (unsigned, _socket_id) = (unsigned )SOCKET_ID_ANY ;RTE_DEFINE_PER_LCORE (rte_cpuset_t, _cpuset);/*
lib/librte_eal/common/include/rte_lcore.h +2 -2
@@ -48,7 +48,7 @@extern "C" {#endif -#define LCORE_ID_ANY -1/**< Any lcore. */ +#define LCORE_ID_ANY UINT32_MAX/**< Any lcore. */ #if defined(__linux__)typedef cpu_set_t rte_cpuset_t ;
@@ -87,7 +87,7 @@ RTE_DECLARE_PER_LCORE(rte_cpuset_t, _cpuset); /**< Per thread "cpuset". *//** * Return the ID of the execution unit we are running on. * @return -* Logical core ID +* Logical core ID(in EAL thread) or LCORE_ID_ANY(in non-EAL thread) */ static inline unsigned rte_lcore_id (void )
lib/librte_eal/linuxapp/eal/eal_thread.c +2 -2
@@ -56,8 +56,8 @@#include "eal_private.h" #include "eal_thread.h" -RTE_DEFINE_PER_LCORE (unsigned, _lcore_id); -RTE_DEFINE_PER_LCORE (unsigned, _socket_id); +RTE_DEFINE_PER_LCORE (unsigned, _lcore_id) =LCORE_ID_ANY ; +RTE_DEFINE_PER_LCORE (unsigned, _socket_id) = (unsigned )SOCKET_ID_ANY ;RTE_DEFINE_PER_LCORE (rte_cpuset_t, _cpuset);/*
Signature · 1 line
1.8.1.4
PATCH v7 15/19 eal: fix recursive spinlock in non-EAL thraed
In reply to a message not in the archiveIn non-EAL thread, lcore_id alrways be LCORE_ID_ANY. It cann't be used as unique id for recursive spinlock. Then use rte_gettid() to replace it.
--- lib/librte_eal/common/include/generic/rte_spinlock.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
lib/librte_eal/common/include/generic/rte_spinlock.h +2 -2
@@ -179,7 +179,7 @@ static inline void rte_spinlock_recursive_init(rte_spinlock_recursive_t *slr)*/ static inline void rte_spinlock_recursive_lock (rte_spinlock_recursive_t *slr) { -int id =rte_lcore_id (); +int id =rte_gettid ();if (slr->user != id) {rte_spinlock_lock (&slr->sl);
@@ -212,7 +212,7 @@ static inline void rte_spinlock_recursive_unlock(rte_spinlock_recursive_t *slr)*/ static inline int rte_spinlock_recursive_trylock (rte_spinlock_recursive_t *slr) { -int id =rte_lcore_id (); +int id =rte_gettid ();if (slr->user != id) {if (rte_spinlock_trylock (&slr->sl) ==0 )
Signature · 1 line
1.8.1.4
PATCH v7 16/19 mempool: add support to non-EAL thread
In reply to a message not in the archiveFor non-EAL thread, bypass per lcore cache, directly use ring pool. It allows using rte_mempool in either EAL thread or any user pthread. As in non-EAL thread, it directly rely on rte_ring and it's none preemptive. It doesn't suggest to run multi-pthread/cpu which compete the rte_mempool. It will get bad performance and has critical risk if scheduling policy is RT. Haven't found significant performance decrease by mempool_perf_test.
---
v6 changes:
rollback v5 changes
v5 changes:
check __lcore_id with LCORE_ID_ANY instead of RTE_MAX_LCORE
lib/librte_mempool/rte_mempool.h | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-)
lib/librte_mempool/rte_mempool.h +11 -7
@@ -198,10 +198,12 @@ struct rte_mempool {* Number to add to the object-oriented statistics. */ #ifdef RTE_LIBRTE_MEMPOOL_DEBUG -#define __MEMPOOL_STAT_ADD (mp, name, n) do { \ - unsigned __lcore_id = rte_lcore_id(); \ - mp->stats[__lcore_id].name##_objs += n; \ - mp->stats[__lcore_id].name##_bulk += 1; \ +#define __MEMPOOL_STAT_ADD (mp, name, n) do { \ + unsigned __lcore_id = rte_lcore_id(); \ + if (__lcore_id < RTE_MAX_LCORE) { \ + mp->stats[__lcore_id].name##_objs += n; \ + mp->stats[__lcore_id].name##_bulk += 1; \ + } \ } while(0)#else #define __MEMPOOL_STAT_ADD (mp, name, n) do {} while(0)
@@ -767,8 +769,9 @@ __mempool_put_bulk(struct rte_mempool *mp, void * const *obj_table,__MEMPOOL_STAT_ADD (mp, put, n);#if RTE_MEMPOOL_CACHE_MAX_SIZE >0 -/* cache is not enabled or single producer */ -if (unlikely (cache_size ==0 || is_mp ==0 )) +/* cache is not enabled or single producer or none EAL thread */ +if (unlikely (cache_size ==0 || is_mp ==0 || + lcore_id >=RTE_MAX_LCORE )) goto ring_enqueue;/* Go straight to ring if put would overflow mem allocated for cache */
@@ -952,7 +955,8 @@ __mempool_get_bulk(struct rte_mempool *mp, void **obj_table,uint32_t cache_size = mp->cache_size;/* cache is not enabled or single consumer */ -if (unlikely (cache_size ==0 || is_mc ==0 || n >= cache_size)) +if (unlikely (cache_size ==0 || is_mc ==0 || + n >= cache_size || lcore_id >=RTE_MAX_LCORE )) goto ring_dequeue; cache = &mp->local_cache[lcore_id];
Signature · 1 line
1.8.1.4
PATCH v7 17/19 ring: add support to non-EAL thread
In reply to a message not in the archivering debug stat won't take care non-EAL thread.
---
v6 changes:
rollback v5 changes
v5 changes:
check __lcore_id with LCORE_ID_ANY instead of RTE_MAX_LCORE
lib/librte_ring/rte_ring.h | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-)
lib/librte_ring/rte_ring.h +6 -4
@@ -188,10 +188,12 @@ struct rte_ring {* The number to add to the object-oriented statistics. */ #ifdef RTE_LIBRTE_RING_DEBUG -#define __RING_STAT_ADD (r, name, n) do { \ - unsigned __lcore_id = rte_lcore_id(); \ - r->stats[__lcore_id].name##_objs += n; \ - r->stats[__lcore_id].name##_bulk += 1; \ +#define __RING_STAT_ADD (r, name, n) do { \ + unsigned __lcore_id = rte_lcore_id(); \ + if (__lcore_id < RTE_MAX_LCORE) { \ + r->stats[__lcore_id].name##_objs += n; \ + r->stats[__lcore_id].name##_bulk += 1; \ + } \ } while(0)#else #define __RING_STAT_ADD (r, name, n) do {} while(0)
Signature · 1 line
1.8.1.4
PATCH v7 18/19 ring: add sched_yield to avoid spin forever
In reply to a message not in the archiveAdd a sched_yield() syscall if the thread spins for too long, waiting other thread to finish its operations on the ring. That gives pre-empted thread a chance to proceed and finish with ring enqnue/dequeue operation.
The purpose is to reduce contention on the ring. By ring_perf_test, it doesn't shows additional perf penalty.
---
v6 changes:
rename RTE_RING_PAUSE_REP to RTE_RING_PAUSE_REP_COUNT set default value as '0' in configure file
v5 changes:
add RTE_RING_PAUSE_REP to config file
v4 changes:
update and add more comments on sched_yield()
v3 changes:
new patch adding sched_yield() in rte_ring to avoid long spin
config/common_bsdapp | 1 + config/common_linuxapp | 1 + lib/librte_ring/rte_ring.h | 31 +++++++++++++++++++++++++++---- 3 files changed, 29 insertions(+), 4 deletions(-)
config/common_bsdapp +1 -0
@@ -234,6 +234,7 @@ CONFIG_RTE_PMD_PACKET_PREFETCH=y CONFIG_RTE_LIBRTE_RING=y CONFIG_RTE_LIBRTE_RING_DEBUG=n CONFIG_RTE_RING_SPLIT_PROD_CONS=n +CONFIG_RTE_RING_PAUSE_REP_COUNT=0 # # Compile librte_mempool
config/common_linuxapp +1 -0
@@ -242,6 +242,7 @@ CONFIG_RTE_PMD_PACKET_PREFETCH=y CONFIG_RTE_LIBRTE_RING=y CONFIG_RTE_LIBRTE_RING_DEBUG=n CONFIG_RTE_RING_SPLIT_PROD_CONS=n +CONFIG_RTE_RING_PAUSE_REP_COUNT=0 # # Compile librte_mempool
lib/librte_ring/rte_ring.h +27 -4
@@ -127,6 +127,11 @@ struct rte_ring_debug_stats {#define RTE_RING_NAMESIZE 32/**< The maximum length of a ring name. */ #define RTE_RING_MZ_PREFIX "RG_" +#ifndef RTE_RING_PAUSE_REP_COUNT +#define RTE_RING_PAUSE_REP_COUNT 0/**< yield after pause num of times, no yield +* if RTE_RING_PAUSE_REP not defined. */ +#endif +/** * An RTE ring structure. *
@@ -410,7 +415,7 @@ __rte_ring_mp_do_enqueue(struct rte_ring *r, void * const *obj_table,uint32_t cons_tail, free_entries;const unsigned max = n;int success; -unsigned i; +unsigned i, rep =0 ;uint32_t mask = r->prod.mask;int ret;
@@ -468,9 +473,18 @@ __rte_ring_mp_do_enqueue(struct rte_ring *r, void * const *obj_table,* If there are other enqueues in progress that preceded us, * we need to wait for them to complete */ -while (unlikely (r->prod.tail != prod_head)) +while (unlikely (r->prod.tail != prod_head)) {rte_pause (); +/* Set RTE_RING_PAUSE_REP_COUNT to avoid spin too long waiting +* for other thread finish. It gives pre-empted thread a chance +* to proceed and finish with ring denqnue operation. */ +if (RTE_RING_PAUSE_REP_COUNT && + ++rep ==RTE_RING_PAUSE_REP_COUNT ) { + rep =0 ; +sched_yield (); + } + } r->prod.tail = prod_next;return ret; }
@@ -589,7 +603,7 @@ __rte_ring_mc_do_dequeue(struct rte_ring *r, void **obj_table,uint32_t cons_next, entries;const unsigned max = n;int success; -unsigned i; +unsigned i, rep =0 ;uint32_t mask = r->prod.mask;/* move cons.head atomically */
@@ -634,9 +648,18 @@ __rte_ring_mc_do_dequeue(struct rte_ring *r, void **obj_table,* If there are other dequeues in progress that preceded us, * we need to wait for them to complete */ -while (unlikely (r->cons.tail != cons_head)) +while (unlikely (r->cons.tail != cons_head)) {rte_pause (); +/* Set RTE_RING_PAUSE_REP_COUNT to avoid spin too long waiting +* for other thread finish. It gives pre-empted thread a chance +* to proceed and finish with ring denqnue operation. */ +if (RTE_RING_PAUSE_REP_COUNT && + ++rep ==RTE_RING_PAUSE_REP_COUNT ) { + rep =0 ; +sched_yield (); + } + }__RING_STAT_ADD (r, deq_success, n); r->cons.tail = cons_next;
Signature · 1 line
1.8.1.4
PATCH v7 19/19 timer: add support to non-EAL thread
In reply to a message not in the archiveAllow to setup timers only for EAL (lcore) threads (__lcore_id < MAX_LCORE_ID). E.g. – dynamically created thread will be able to reset/stop timer for lcore thread, but it will be not allowed to setup timer for itself or another non-lcore thread. rte_timer_manage() for non-lcore thread would simply do nothing and return straightway.
---
v6 changes:
use 'RTE_MAX_LCORE' to check the EAL thread with valid lcore_id. use 'LCORE_ID_ANY' for any unspecified lcore_id assignment.
v5 changes:
add assert in rte_timer_manage
remove duplicate check in timer_set_config_state
lib/librte_timer/rte_timer.c | 32 +++++++++++++++++++++++--------- lib/librte_timer/rte_timer.h | 4 ++-- 2 files changed, 25 insertions(+), 11 deletions(-)
lib/librte_timer/rte_timer.c +23 -9
@@ -35,6 +35,7 @@#include <stdio.h> #include <stdint.h> #include <inttypes.h> +#include <assert.h> #include <rte_atomic.h> #include <rte_common.h>
@@ -79,9 +80,10 @@ static struct priv_timer priv_timer[RTE_MAX_LCORE];/* when debug is enabled, store some statistics */ #ifdef RTE_LIBRTE_TIMER_DEBUG -#define __TIMER_STAT_ADD (name, n) do { \ - unsigned __lcore_id = rte_lcore_id(); \ - priv_timer[__lcore_id].stats.name += (n); \ +#define __TIMER_STAT_ADD (name, n) do { \ + unsigned __lcore_id = rte_lcore_id(); \ + if (__lcore_id < RTE_MAX_LCORE) \ + priv_timer[__lcore_id].stats.name += (n); \ } while(0)#else #define __TIMER_STAT_ADD (name, n) do {} while(0)
@@ -135,7 +137,7 @@ timer_set_config_state(struct rte_timer *tim,/* timer is running on another core, exit */ if (prev_status.state ==RTE_TIMER_RUNNING && - (unsigned )prev_status.owner != lcore_id) + prev_status.owner != (uint16_t )lcore_id)return -1 ;/* timer is being configured on another core */
@@ -366,9 +368,16 @@ __rte_timer_reset(struct rte_timer *tim, uint64_t expire,/* round robin for tim_lcore */ if (tim_lcore == (unsigned )LCORE_ID_ANY ) { - tim_lcore =rte_get_next_lcore (priv_timer[lcore_id].prev_lcore, -0 ,1 ); - priv_timer[lcore_id].prev_lcore = tim_lcore; +if (lcore_id <RTE_MAX_LCORE ) { +/* EAL thread with valid lcore_id */ + tim_lcore =rte_get_next_lcore ( + priv_timer[lcore_id].prev_lcore, +0 ,1 ); + priv_timer[lcore_id].prev_lcore = tim_lcore; + }else +/* non-EAL thread do not run rte_timer_manage(), +* so schedule the timer on the first enabled lcore. */ + tim_lcore =rte_get_next_lcore (LCORE_ID_ANY ,0 ,1 ); }/* wait that the timer is in correct status before update,
@@ -378,7 +387,8 @@ __rte_timer_reset(struct rte_timer *tim, uint64_t expire,return -1 ;__TIMER_STAT_ADD (reset,1 ); -if (prev_status.state ==RTE_TIMER_RUNNING ) { +if (prev_status.state ==RTE_TIMER_RUNNING && + lcore_id <RTE_MAX_LCORE ) { priv_timer[lcore_id].updated =1 ; }
@@ -455,7 +465,8 @@ rte_timer_stop(struct rte_timer *tim)return -1 ;__TIMER_STAT_ADD (stop,1 ); -if (prev_status.state ==RTE_TIMER_RUNNING ) { +if (prev_status.state ==RTE_TIMER_RUNNING && + lcore_id <RTE_MAX_LCORE ) { priv_timer[lcore_id].updated =1 ; }
@@ -499,6 +510,9 @@ void rte_timer_manage(void)uint64_t cur_time;int i, ret; +/* timer manager only runs on EAL thread with valid lcore_id */ +assert (lcore_id <RTE_MAX_LCORE ); +__TIMER_STAT_ADD (manage,1 );/* optimize for the case where per-cpu list is empty */ if (priv_timer[lcore_id].pending_head.sl_next[0 ] ==NULL )
lib/librte_timer/rte_timer.h +2 -2
@@ -76,7 +76,7 @@ extern "C" {#define RTE_TIMER_RUNNING 2/**< State: timer function is running. */ #define RTE_TIMER_CONFIG 3/**< State: timer is being configured. */ -#define RTE_TIMER_NO_OWNER -1/**< Timer has no owner. */ +#define RTE_TIMER_NO_OWNER -2/**< Timer has no owner. */ /** * Timer type: Periodic or single (one-shot).
@@ -310,7 +310,7 @@ int rte_timer_pending(struct rte_timer *tim);/** * Manage the timer list and execute callback functions. * -* This function must be called periodically from all cores +* This function must be called periodically from EAL lcores * main_loop(). It browses the list of pending timers and runs all * timers that are expired. *
Signature · 1 line
1.8.1.4
v8 cover support multi-pthread per core
In reply to a message not in the archivev8 changes:
keep using strlen for trusted input string
v7 changes:
update EAL version map for new public EAL API rollback to use strnlen() passing EAL core option
v6 changes:
rename RTE_RING_PAUSE_REP(_COUNT) and set default to 0 rollback to use RTE_MAX_LCORE when checking valid lcore_id for EAL thread
v5 changes:
reorder some patch and split into addtional two patches rte_thread_get_affinity() return type change to avoid add RTE_RING_PAUSE_REP into config and by default turn off
v4 changes:
new patch fixing strnlen() invalid return in 32bit icc [03/17] update and add more comments on sched_yield() [16/17]
v3 changes:
new patch adding sched_yield() in rte_ring to avoid long spin [16/17]
v2 changes:
add '<number>-<number>' support for EAL option '--lcores' [02/17]
The patch series contain the enhancements of EAL and fixes for libraries
to run multi-pthreads(either EAL or non-EAL thread) per physical core.
Two major changes list as below:
- Extend the core affinity of each EAL thread to 1:n.
Each lcore stands for a EAL thread rather than a logical core.
The change adds new EAL option to allow static lcore to cpuset assginment. Then a lcore(EAL thread) affinity to a cpuset, original 1:1 mapping is the special case.
- Fix the libraries to allow running on any non-EAL thread.
It fix the gaps running libraries in non-EAL thread(dynamic created by user). Each fix libraries take care the case of rte_lcore_id() >= RTE_MAX_LCORE.
Thanks a million for the comments from Konstantin, Bruce, Mirek and Stephen in RFC review.
Cunming Liang (19):
eal: add cpuset into per EAL thread lcore_config
eal: fix PAGE_SIZE redefine complaint on freebsd
eal: new eal option '--lcores' for cpu assignment
eal: fix wrong strnlen() return value in 32bit icc
eal: add public function parsing socket_id from cpu_id
eal: new TLS definition and API declaration
eal: add eal_common_thread.c for common thread API
eal: standardize init sequence between linux and bsd
eal: add rte_gettid() to acquire unique system tid
eal: apply affinity of EAL thread by assigned cpuset
enic: fix re-define freebsd compile complain
malloc: fix the issue of SOCKET_ID_ANY
log: fix the gap to support non-EAL thread
eal: set _lcore_id and _socket_id to (-1) by default
eal: fix recursive spinlock in non-EAL thraed
mempool: add support to non-EAL thread
ring: add support to non-EAL thread
ring: add sched_yield to avoid spin forever
timer: add support to non-EAL thread
config/common_bsdapp | 1 + config/common_linuxapp | 1 + lib/librte_eal/bsdapp/eal/Makefile | 1 + lib/librte_eal/bsdapp/eal/eal.c | 14 +- lib/librte_eal/bsdapp/eal/eal_lcore.c | 14 + lib/librte_eal/bsdapp/eal/eal_memory.c | 8 +- lib/librte_eal/bsdapp/eal/eal_thread.c | 77 ++---- lib/librte_eal/bsdapp/eal/rte_eal_version.map | 2 + lib/librte_eal/common/eal_common_log.c | 17 +- lib/librte_eal/common/eal_common_options.c | 308 ++++++++++++++++++++- lib/librte_eal/common/eal_common_thread.c | 150 ++++++++++ lib/librte_eal/common/eal_options.h | 2 + lib/librte_eal/common/eal_thread.h | 47 ++++ .../common/include/generic/rte_spinlock.h | 4 +- lib/librte_eal/common/include/rte_eal.h | 27 ++ lib/librte_eal/common/include/rte_lcore.h | 40 ++- lib/librte_eal/common/include/rte_log.h | 5 + lib/librte_eal/linuxapp/eal/Makefile | 4 + lib/librte_eal/linuxapp/eal/eal.c | 8 +- lib/librte_eal/linuxapp/eal/eal_lcore.c | 15 +- lib/librte_eal/linuxapp/eal/eal_thread.c | 77 ++---- lib/librte_eal/linuxapp/eal/rte_eal_version.map | 2 + lib/librte_malloc/malloc_heap.h | 7 +- lib/librte_mempool/rte_mempool.h | 18 +- lib/librte_pmd_enic/enic.h | 4 +- lib/librte_pmd_enic/enic_compat.h | 2 +- lib/librte_pmd_enic/vnic/vnic_dev.c | 6 +- lib/librte_ring/rte_ring.h | 41 ++- lib/librte_timer/rte_timer.c | 32 ++- lib/librte_timer/rte_timer.h | 4 +- 30 files changed, 769 insertions(+), 169 deletions(-) create mode 100644 lib/librte_eal/common/eal_common_thread.c
Signature · 1 line
1.8.1.4
A message that is not in the archive (sent off-list or not yet received): 1424138896-28618-1-git-send-email-cunming.liang-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org
PATCH v8 1/19 eal: add cpuset into per EAL thread lcore_config
The patch adds 'cpuset' into per-lcore configure 'lcore_config[]', as the lcore no longer always 1:1 pinning with physical cpu. The lcore now stands for a EAL thread rather than a logical cpu.
It doesn't change the default behavior of 1:1 mapping, but allows to affinity the EAL thread to multiple cpus.
---
v5 changes:
separate eal_memory.c to the new patch
lib/librte_eal/bsdapp/eal/eal_lcore.c | 7 +++++++ lib/librte_eal/common/include/rte_lcore.h | 8 ++++++++ lib/librte_eal/linuxapp/eal/Makefile | 1 + lib/librte_eal/linuxapp/eal/eal_lcore.c | 8 ++++++++ 4 files changed, 24 insertions(+)
lib/librte_eal/bsdapp/eal/eal_lcore.c +7 -0
@@ -76,11 +76,18 @@ rte_eal_cpu_init(void)* ones and enable them by default. */ for (lcore_id =0 ; lcore_id <RTE_MAX_LCORE ; lcore_id++) { +/* init cpuset for per lcore config */ +CPU_ZERO (&lcore_config[lcore_id].cpuset); + lcore_config[lcore_id].detected = (lcore_id < ncpus);if (lcore_config[lcore_id].detected ==0 ) { config->lcore_role[lcore_id] =ROLE_OFF ;continue ; } + +/* By default, lcore 1:1 map to cpu id */ +CPU_SET (lcore_id, &lcore_config[lcore_id].cpuset); +/* By default, each detected core is enabled */ config->lcore_role[lcore_id] =ROLE_RTE ; lcore_config[lcore_id].core_id =cpu_core_id (lcore_id);
lib/librte_eal/common/include/rte_lcore.h +8 -0
@@ -50,6 +50,13 @@ extern "C" {#define LCORE_ID_ANY -1/**< Any lcore. */ +#if defined(__linux__) +typedef cpu_set_t rte_cpuset_t ; +#elif defined(__FreeBSD__) +#include <pthread_np.h> +typedef cpuset_t rte_cpuset_t ; +#endif +/** * Structure storing internal configuration (per-lcore) */
@@ -65,6 +72,7 @@ struct lcore_config {unsigned socket_id;/**< physical socket id for this lcore */ unsigned core_id;/**< core number on socket for this lcore */ int core_index;/**< relative index, starting from 0 */ +rte_cpuset_t cpuset;/**< cpu set which the lcore affinity to */ };/**
lib/librte_eal/linuxapp/eal/Makefile +1 -0
@@ -91,6 +91,7 @@ SRCS-$(CONFIG_RTE_LIBRTE_EAL_LINUXAPP) += eal_common_dev.c SRCS-$(CONFIG_RTE_LIBRTE_EAL_LINUXAPP) += eal_common_options.c CFLAGS_eal.o := -D_GNU_SOURCE +CFLAGS_eal_lcore.o := -D_GNU_SOURCE CFLAGS_eal_thread.o := -D_GNU_SOURCE CFLAGS_eal_log.o := -D_GNU_SOURCE CFLAGS_eal_common_log.o := -D_GNU_SOURCE
lib/librte_eal/linuxapp/eal/eal_lcore.c +8 -0
@@ -158,11 +158,19 @@ rte_eal_cpu_init(void)* ones and enable them by default. */ for (lcore_id =0 ; lcore_id <RTE_MAX_LCORE ; lcore_id++) { +/* init cpuset for per lcore config */ +CPU_ZERO (&lcore_config[lcore_id].cpuset); + +/* in 1:1 mapping, record related cpu detected state */ lcore_config[lcore_id].detected =cpu_detected (lcore_id);if (lcore_config[lcore_id].detected ==0 ) { config->lcore_role[lcore_id] =ROLE_OFF ;continue ; } + +/* By default, lcore 1:1 map to cpu id */ +CPU_SET (lcore_id, &lcore_config[lcore_id].cpuset); +/* By default, each detected core is enabled */ config->lcore_role[lcore_id] =ROLE_RTE ; lcore_config[lcore_id].core_id =cpu_core_id (lcore_id);
Signature · 1 line
1.8.1.4
PATCH v8 2/19 eal: fix PAGE_SIZE redefine complaint on freebsd
In reply to a message not in the archive--- lib/librte_eal/bsdapp/eal/eal_memory.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-)
lib/librte_eal/bsdapp/eal/eal_memory.c +5 -3
@@ -45,7 +45,7 @@#include "eal_internal_cfg.h" #include "eal_filesystem.h" -#define PAGE_SIZE (sysconf(_SC_PAGESIZE)) +#define EAL_PAGE_SIZE (sysconf(_SC_PAGESIZE))/* * Get physical address of any mapped virtual address in the current process.
@@ -93,7 +93,8 @@ rte_eal_contigmem_init(void)char physaddr_str[64 ]; addr =mmap (NULL , hpi->hugepage_sz,PROT_READ |PROT_WRITE , -MAP_SHARED , hpi->lock_descriptor, j *PAGE_SIZE ); +MAP_SHARED , hpi->lock_descriptor, + j *EAL_PAGE_SIZE );if (addr ==MAP_FAILED ) {RTE_LOG (ERR ,EAL ,"Failed to mmap buffer %u from %s\n" , j, hpi->hugedir);
@@ -167,7 +168,8 @@ rte_eal_contigmem_attach(void)struct rte_memseg *seg = &mcfg->memseg[i]; addr =mmap (seg->addr, hpi->hugepage_sz,PROT_READ |PROT_WRITE , -MAP_SHARED |MAP_FIXED , fd_hugepage, i *PAGE_SIZE ); +MAP_SHARED |MAP_FIXED , fd_hugepage, + i *EAL_PAGE_SIZE );if (addr ==MAP_FAILED || addr != seg->addr) {RTE_LOG (ERR ,EAL ,"Failed to mmap buffer %u from %s\n" , i, hpi->hugedir);
Signature · 1 line
1.8.1.4
PATCH v8 3/19 eal: new eal option '--lcores' for cpu assignment
In reply to a message not in the archiveIt supports one new eal long option '--lcores' for EAL thread cpuset assignment.
The format pattern:
--lcores='<lcores[@cpus]>[<,lcores[@cpus]>...]'
lcores, cpus could be a single digit/range or a group. '(' and ')' are necessary if it's a group.
If not supply '@cpus', the value of cpus uses the same as lcores.
e.g. '1,2@(5-7),(3-5)@(0,2),(0,6),7-8' means starting 9 EAL thread as below
lcore 0 runs on cpuset 0x41 (cpu 0,6)
lcore 1 runs on cpuset 0x2 (cpu 1)
lcore 2 runs on cpuset 0xe0 (cpu 5,6,7)
lcore 3,4,5 runs on cpuset 0x5 (cpu 0,2)
lcore 6 runs on cpuset 0x41 (cpu 0,6)
lcore 7 runs on cpuset 0x80 (cpu 7)
lcore 8 runs on cpuset 0x100 (cpu 8)
---
v5 changes:
add more comments for eal_parse_set
fix some typo
remove inline prefix from convert_to_cpuset() fix a bug introduced on v2 which broke case '(0,6)'
v2 changes:
add '<number>-<number>' support for EAL option '--lcores'
lib/librte_eal/common/eal_common_options.c | 304 ++++++++++++++++++++++++++++- lib/librte_eal/common/eal_options.h | 2 + lib/librte_eal/linuxapp/eal/Makefile | 1 + 3 files changed, 303 insertions(+), 4 deletions(-)
lib/librte_eal/common/eal_common_options.c +300 -4
@@ -45,6 +45,7 @@#include <rte_lcore.h> #include <rte_version.h> #include <rte_devargs.h> +#include <rte_memcpy.h> #include "eal_internal_cfg.h" #include "eal_options.h"
@@ -85,6 +86,7 @@ eal_long_options[] = { {OPT_XEN_DOM0, 0, 0, OPT_XEN_DOM0_NUM}, {OPT_CREATE_UIO_DEV, 1, NULL, OPT_CREATE_UIO_DEV_NUM}, {OPT_VFIO_INTR, 1, NULL, OPT_VFIO_INTR_NUM}, + {OPT_LCORES, 1, 0, OPT_LCORES_NUM}, {0, 0, 0, 0} };
@@ -255,9 +257,11 @@ eal_parse_corelist(const char *corelist)if (min ==RTE_MAX_LCORE ) min = idx;for (idx = min; idx <= max; idx++) { - cfg->lcore_role[idx] =ROLE_RTE ; - lcore_config[idx].core_index = count; - count++; +if (cfg->lcore_role[idx] !=ROLE_RTE ) { + cfg->lcore_role[idx] =ROLE_RTE ; + lcore_config[idx].core_index = count; + count++; + } } min =RTE_MAX_LCORE ; }else
@@ -292,6 +296,283 @@ eal_parse_master_lcore(const char *arg)return 0 ; } +/* +* Parse elem, the elem could be single number/range or '(' ')' group +* 1) A single number elem, it's just a simple digit. e.g. 9 +* 2) A single range elem, two digits with a '-' between. e.g. 2-6 +* 3) A group elem, combines multiple 1) or 2) with '( )'. e.g (0,2-4,6) +* Within group elem, '-' used for a range separator; +* ',' used for a single number. +*/ +static int +eal_parse_set (const char *input,uint16_t set[],unsigned num) +{ +unsigned idx; +const char *str = input; +char *end =NULL ; +unsigned min, max; + +memset (set,0 , num *sizeof (uint16_t )); + +while (isblank (*str)) + str++; + +/* only digit or left bracket is qualify for start point */ +if ((!isdigit (*str) && *str !='(' ) || *str =='\0' ) +return -1 ; + +/* process single number or single range of number */ +if (*str !='(' ) { + errno =0 ; + idx =strtoul (str, &end,10 ); +if (errno || end ==NULL || idx >= num) +return -1 ; +else { +while (isblank (*end)) + end++; + + min = idx; + max = idx; +if (*end =='-' ) { +/* process single <number>-<number> */ + end++; +while (isblank (*end)) + end++; +if (!isdigit (*end)) +return -1 ; + + errno =0 ; + idx =strtoul (end, &end,10 ); +if (errno || end ==NULL || idx >= num) +return -1 ; + max = idx; +while (isblank (*end)) + end++; +if (*end !=',' && *end !='\0' ) +return -1 ; + } + +if (*end !=',' && *end !='\0' && + *end !='@' ) +return -1 ; + +for (idx =RTE_MIN (min, max); + idx <=RTE_MAX (min, max); idx++) + set[idx] =1 ; + +return end - input; + } + } + +/* process set within bracket */ + str++; +while (isblank (*str)) + str++; +if (*str =='\0' ) +return -1 ; + + min =RTE_MAX_LCORE ; +do { + +/* go ahead to the first digit */ +while (isblank (*str)) + str++; +if (!isdigit (*str)) +return -1 ; + +/* get the digit value */ + errno =0 ; + idx =strtoul (str, &end,10 ); +if (errno || end ==NULL || idx >= num) +return -1 ; + +/* go ahead to separator '-',',' and ')' */ +while (isblank (*end)) + end++; +if (*end =='-' ) { +if (min ==RTE_MAX_LCORE ) + min = idx; +else /* avoid continuous '-' */ +return -1 ; + }else if ((*end ==',' ) || (*end ==')' )) { + max = idx; +if (min ==RTE_MAX_LCORE ) + min = idx; +for (idx =RTE_MIN (min, max); + idx <=RTE_MAX (min, max); idx++) + set[idx] =1 ; + + min =RTE_MAX_LCORE ; + }else +return -1 ; + + str = end +1 ; + }while (*end !='\0' && *end !=')' ); + +return str - input; +} + +/* convert from set array to cpuset bitmap */ +static int +convert_to_cpuset (rte_cpuset_t *cpusetp, +uint16_t *set,unsigned num) +{ +unsigned idx; + +CPU_ZERO (cpusetp); + +for (idx =0 ; idx < num; idx++) { +if (!set[idx]) +continue ; + +if (!lcore_config[idx].detected) { +RTE_LOG (ERR ,EAL ,"core %u " +"unavailable\n" , idx); +return -1 ; + } + +CPU_SET (idx, cpusetp); + } + +return 0 ; +} + +/* +* The format pattern: --lcores='<lcores[@cpus]>[<,lcores[@cpus]>...]' +* lcores, cpus could be a single digit/range or a group. +* '(' and ')' are necessary if it's a group. +* If not supply '@cpus', the value of cpus uses the same as lcores. +* e.g. '1,2@(5-7),(3-5)@(0,2),(0,6),7-8' means start 9 EAL thread as below +* lcore 0 runs on cpuset 0x41 (cpu 0,6) +* lcore 1 runs on cpuset 0x2 (cpu 1) +* lcore 2 runs on cpuset 0xe0 (cpu 5,6,7) +* lcore 3,4,5 runs on cpuset 0x5 (cpu 0,2) +* lcore 6 runs on cpuset 0x41 (cpu 0,6) +* lcore 7 runs on cpuset 0x80 (cpu 7) +* lcore 8 runs on cpuset 0x100 (cpu 8) +*/ +static int +eal_parse_lcores (const char *lcores) +{ +struct rte_config *cfg =rte_eal_get_configuration (); +static uint16_t set[RTE_MAX_LCORE ]; +unsigned idx =0 ; +int i; +unsigned count =0 ; +const char *lcore_start =NULL ; +const char *end =NULL ; +int offset; +rte_cpuset_t cpuset; +int lflags =0 ; +int ret =-1 ; + +if (lcores ==NULL ) +return -1 ; + +/* Remove all blank characters ahead and after */ +while (isblank (*lcores)) + lcores++; + i =strnlen (lcores,sysconf (_SC_ARG_MAX)); +while ((i >0 ) &&isblank (lcores[i -1 ])) + i--; + +CPU_ZERO (&cpuset); + +/* Reset lcore config */ +for (idx =0 ; idx <RTE_MAX_LCORE ; idx++) { + cfg->lcore_role[idx] =ROLE_OFF ; + lcore_config[idx].core_index =-1 ; +CPU_ZERO (&lcore_config[idx].cpuset); + } + +/* Get list of cores */ +do { +while (isblank (*lcores)) + lcores++; +if (*lcores =='\0' ) + goto err; + +/* record lcore_set start point */ + lcore_start = lcores; + +/* go across a complete bracket */ +if (*lcore_start =='(' ) { + lcores +=strcspn (lcores,")" ); +if (*lcores++ =='\0' ) + goto err; + } + +/* scan the separator '@', ','(next) or '\0'(finish) */ + lcores +=strcspn (lcores,"@," ); + +if (*lcores =='@' ) { +/* explict assign cpu_set */ + offset =eal_parse_set (lcores +1 , set,RTE_DIM (set)); +if (offset <0 ) + goto err; + +/* prepare cpu_set and update the end cursor */ +if (0 >convert_to_cpuset (&cpuset, + set,RTE_DIM (set))) + goto err; + end = lcores +1 + offset; + }else {/* ',' or '\0' */ +/* haven't given cpu_set, current loop done */ + end = lcores; + +/* go back to check <number>-<number> */ + offset =strcspn (lcore_start,"(-" ); +if (offset < (end - lcore_start) && + *(lcore_start + offset) !='(' ) + lflags =1 ; + } + +if (*end !=',' && *end !='\0' ) + goto err; + +/* parse lcore_set from start point */ +if (0 >eal_parse_set (lcore_start, set,RTE_DIM (set))) + goto err; + +/* without '@', by default using lcore_set as cpu_set */ +if (*lcores !='@' && +0 >convert_to_cpuset (&cpuset, set,RTE_DIM (set))) + goto err; + +/* start to update lcore_set */ +for (idx =0 ; idx <RTE_MAX_LCORE ; idx++) { +if (!set[idx]) +continue ; + +if (cfg->lcore_role[idx] !=ROLE_RTE ) { + lcore_config[idx].core_index = count; + cfg->lcore_role[idx] =ROLE_RTE ; + count++; + } + +if (lflags) { +CPU_ZERO (&cpuset); +CPU_SET (idx, &cpuset); + } +rte_memcpy (&lcore_config[idx].cpuset, &cpuset, +sizeof (rte_cpuset_t)); + } + + lcores = end +1 ; + }while (*end !='\0' ); + +if (count ==0 ) + goto err; + + cfg->lcore_count = count; + lcores_parsed =1 ; + ret =0 ; + +err: + +return ret; +} +static int eal_parse_syslog (const char *facility,struct internal_config *conf) {
@@ -492,6 +773,13 @@ eal_parse_common_option(int opt, const char *optarg, conf->log_level = log;break ; } +case OPT_LCORES_NUM : +if (eal_parse_lcores (optarg) <0 ) { +RTE_LOG (ERR ,EAL ,"invalid parameter for --" +OPT_LCORES "\n" ); +return -1 ; + } +break ;/* don't know what to do, leave this to caller */ default :
@@ -530,7 +818,7 @@ eal_check_common_options(struct internal_config *internal_cfg)if (!lcores_parsed) {RTE_LOG (ERR ,EAL ,"CPU cores must be enabled with options " -"-c or -l\n" ); +"-c, -l or --lcores\n" );return -1 ; }if (cfg->lcore_role[cfg->master_lcore] !=ROLE_RTE ) {
@@ -586,6 +874,14 @@ eal_common_usage(void)" The argument format is <c1>[-c2][,c3[-c4],...]\n" " where c1, c2, etc are core indexes between 0 and %d\n" " --" OPT_MASTER_LCORE " ID: Core ID that is used as master\n" +" --" OPT_LCORES " MAP: maps between lcore_set to phys_cpu_set\n" +" The argument format is\n" +" '<lcores[@cpus]>[<,lcores[@cpus]>...]'\n" +" lcores and cpus list are grouped by '(' and ')'\n" +" Within the group, '-' is used for range separator,\n" +" ',' is used for single number separator.\n" +" '( )' can be omitted for single element group, '@' \n" +" can be omitted if cpus and lcores has the same value\n" " -n NUM : Number of memory channels\n" " -v : Display version information on startup\n" " -m MB : memory to allocate (see also --" OPT_SOCKET_MEM ")\n"
lib/librte_eal/common/eal_options.h +2 -0
@@ -77,6 +77,8 @@ enum {OPT_CREATE_UIO_DEV_NUM , #define OPT_VFIO_INTR "vfio-intr"OPT_VFIO_INTR_NUM , +#define OPT_LCORES "lcores" +OPT_LCORES_NUM , OPT_LONG_MAX_NUM };
lib/librte_eal/linuxapp/eal/Makefile +1 -0
@@ -99,6 +99,7 @@ CFLAGS_eal_hugepage_info.o := -D_GNU_SOURCE CFLAGS_eal_pci.o := -D_GNU_SOURCE CFLAGS_eal_pci_vfio.o := -D_GNU_SOURCE CFLAGS_eal_common_whitelist.o := -D_GNU_SOURCE +CFLAGS_eal_common_options.o := -D_GNU_SOURCE # workaround for a gcc bug with noreturn attribute # http://gcc.gnu.org/bugzilla/show_bug.cgi?id=12603
Signature · 1 line
1.8.1.4
PATCH v8 4/19 eal: fix wrong strnlen() return value in 32bit icc
In reply to a message not in the archiveThe problem is that strnlen() here may return invalid value with 32bit icc. (actually it returns it’s second parameter,e.g: sysconf(_SC_ARG_MAX)).
It starts to manifest hwen max_len parameter is > 2M and using icc –m32 –O2 (or above).
---
v8 changes:
keep using strlen for trusted input string
v7 changes:
rollback to use strnlen
v5 changes:
using strlen instead of strnlen.
lib/librte_eal/common/eal_common_options.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
lib/librte_eal/common/eal_common_options.c +3 -3
@@ -167,7 +167,7 @@ eal_parse_coremask(const char *coremask)if (coremask[0 ] =='0' && ((coremask[1 ] =='x' ) || (coremask[1 ] =='X' ))) coremask +=2 ; - i =strnlen (coremask,PATH_MAX ); + i =strlen (coremask);while ((i >0 ) &&isblank (coremask[i -1 ])) i--;if (i ==0 )
@@ -227,7 +227,7 @@ eal_parse_corelist(const char *corelist)/* Remove all blank characters ahead and after */ while (isblank (*corelist)) corelist++; - i =strnlen (corelist,sysconf (_SC_ARG_MAX)); + i =strlen (corelist);while ((i >0 ) &&isblank (corelist[i -1 ])) i--;
@@ -472,7 +472,7 @@ eal_parse_lcores(const char *lcores)/* Remove all blank characters ahead and after */ while (isblank (*lcores)) lcores++; - i =strnlen (lcores,sysconf (_SC_ARG_MAX)); + i =strlen (lcores);while ((i >0 ) &&isblank (lcores[i -1 ])) i--;
Signature · 1 line
1.8.1.4
PATCH v8 5/19 eal: add public function parsing socket_id from cpu_id
In reply to a message not in the archiveIt defines eal_cpu_socket_id() which exposing the origin private cpu_socket_id(). The function is only used inside EAL. It returns socket_id of the specified cpu_id.
---
v7 changes:
reword comments
v5 changes:
expose cpu_socket_id as eal_cpu_socket_id for linuxapp eal_cpuset_socket_id() remove static inline and move to c file
lib/librte_eal/bsdapp/eal/eal_lcore.c | 7 +++++++ lib/librte_eal/common/eal_thread.h | 11 +++++++++++ lib/librte_eal/linuxapp/eal/eal_lcore.c | 7 ++++--- 3 files changed, 22 insertions(+), 3 deletions(-)
lib/librte_eal/bsdapp/eal/eal_lcore.c +7 -0
@@ -41,6 +41,7 @@#include <rte_debug.h> #include "eal_private.h" +#include "eal_thread.h" /* No topology information available on FreeBSD including NUMA info */ #define cpu_core_id (X ) 0
@@ -112,3 +113,9 @@ rte_eal_cpu_init(void)return 0 ; } + +unsigned +eal_cpu_socket_id (__rte_unused unsigned cpu_id) +{ +return cpu_socket_id (cpu_id); +}
lib/librte_eal/common/eal_thread.h +11 -0
@@ -50,4 +50,15 @@ __attribute__((noreturn)) void *eal_thread_loop(void *arg);*/ void eal_thread_init_master (unsigned lcore_id); +/** +* Get the NUMA socket id from cpu id. +* This function is private to EAL. +* +* @param cpu_id +* The logical process id. +* @return +* socket_id or SOCKET_ID_ANY +*/ +unsigned eal_cpu_socket_id (unsigned cpu_id); +#endif /* EAL_THREAD_H */
lib/librte_eal/linuxapp/eal/eal_lcore.c +4 -3
@@ -45,6 +45,7 @@#include "eal_private.h" #include "eal_filesystem.h" +#include "eal_thread.h" #define SYS_CPU_DIR "/sys/devices/system/cpu/cpu%u"#define CORE_ID_FILE "topology/core_id"
@@ -71,8 +72,8 @@ cpu_detected(unsigned lcore_id)* Note: physical package id != NUMA node, but we use it as a * fallback for kernels which don't create a nodeY link */ -static unsigned -cpu_socket_id (unsigned lcore_id) +unsigned +eal_cpu_socket_id (unsigned lcore_id) {const char node_prefix[] ="node" ;const size_t prefix_len =sizeof (node_prefix) -1 ;
@@ -174,7 +175,7 @@ rte_eal_cpu_init(void)/* By default, each detected core is enabled */ config->lcore_role[lcore_id] =ROLE_RTE ; lcore_config[lcore_id].core_id =cpu_core_id (lcore_id); - lcore_config[lcore_id].socket_id =cpu_socket_id (lcore_id); + lcore_config[lcore_id].socket_id =eal_cpu_socket_id (lcore_id); if (lcore_config[lcore_id].socket_id >= RTE_MAX_NUMA_NODES)#ifdef RTE_EAL_ALLOW_INV_SOCKET_ID lcore_config[lcore_id].socket_id =0 ;
Signature · 1 line
1.8.1.4
PATCH v8 6/19 eal: new TLS definition and API declaration
In reply to a message not in the archive1. add two TLS *_socket_id* and *_cpuset*
2. add one internal API, eal_cpu_socket_id/eal_thread_dump_affinity
3. add two public API, rte_thread_set/get_affinity
4. update EAL version map for EAL public API
---
v7 changes:
update version map for EAL public API and reword comments
v5 changes:
add comments for RTE_CPU_AFFINITY_STR_LEN
update comments for eal_thread_dump_affinity()
return void for rte_thread_get_affinity()
move rte_socket_id() change to another patch
lib/librte_eal/bsdapp/eal/eal_thread.c | 2 ++ lib/librte_eal/bsdapp/eal/rte_eal_version.map | 2 ++ lib/librte_eal/common/eal_thread.h | 36 +++++++++++++++++++++++++ lib/librte_eal/common/include/rte_lcore.h | 26 +++++++++++++++++- lib/librte_eal/linuxapp/eal/eal_thread.c | 2 ++ lib/librte_eal/linuxapp/eal/rte_eal_version.map | 2 ++ 6 files changed, 69 insertions(+), 1 deletion(-)
lib/librte_eal/bsdapp/eal/eal_thread.c +2 -0
@@ -56,6 +56,8 @@#include "eal_thread.h" RTE_DEFINE_PER_LCORE (unsigned, _lcore_id); +RTE_DEFINE_PER_LCORE (unsigned, _socket_id); +RTE_DEFINE_PER_LCORE (rte_cpuset_t, _cpuset);/* * Send a message to a slave lcore identified by slave_id to call a
lib/librte_eal/bsdapp/eal/rte_eal_version.map +2 -0
@@ -82,6 +82,8 @@ DPDK_2.0 { rte_snprintf; rte_strerror; rte_strsplit; + rte_thread_get_affinity; + rte_thread_set_affinity; rte_vlog; rte_xen_dom0_memory_attach; rte_xen_dom0_memory_init;
lib/librte_eal/common/eal_thread.h +36 -0
@@ -34,6 +34,8 @@#ifndef EAL_THREAD_H #define EAL_THREAD_H +#include <rte_lcore.h> +/** * basic loop of thread, called for each thread by eal_init(). *
@@ -61,4 +63,38 @@ void eal_thread_init_master(unsigned lcore_id);*/ unsigned eal_cpu_socket_id (unsigned cpu_id); +/** +* Get the NUMA socket id from cpuset. +* This function is private to EAL. +* +* @param cpusetp +* The point to a valid cpu set. +* @return +* socket_id or SOCKET_ID_ANY +*/ +int eal_cpuset_socket_id (rte_cpuset_t *cpusetp); + +/** +* Default buffer size to use with eal_thread_dump_affinity() +*/ +#define RTE_CPU_AFFINITY_STR_LEN 256 + +/** +* Dump the current pthread cpuset. +* This function is private to EAL. +* +* Note: +* If the dump size is greater than the size of given buffer, +* the string will be truncated and with '\0' at the end. +* +* @param str +* The string buffer the cpuset will dump to. +* @param size +* The string buffer size. +* @return +* 0 for success, -1 if truncation happens. +*/ +int +eal_thread_dump_affinity (char *str,unsigned size); +#endif /* EAL_THREAD_H */
lib/librte_eal/common/include/rte_lcore.h +25 -1
@@ -80,7 +80,9 @@ struct lcore_config {*/ extern struct lcore_config lcore_config[RTE_MAX_LCORE ]; -RTE_DECLARE_PER_LCORE (unsigned, _lcore_id);/**< Per core "core id". */ +RTE_DECLARE_PER_LCORE (unsigned, _lcore_id);/**< Per thread "lcore id". */ +RTE_DECLARE_PER_LCORE (unsigned, _socket_id);/**< Per thread "socket id". */ +RTE_DECLARE_PER_LCORE (rte_cpuset_t, _cpuset);/**< Per thread "cpuset". */ /** * Return the ID of the execution unit we are running on.
@@ -229,6 +231,28 @@ rte_get_next_lcore(unsigned i, int skip_master, int wrap) i<RTE_MAX_LCORE ; \ i = rte_get_next_lcore(i, 1, 0)) +/** +* Set core affinity of the current thread. +* Support both EAL and none-EAL thread and update TLS. +* +* @param cpusetp +* Point to cpu_set_t for setting current thread affinity. +* @return +* On success, return 0; otherwise return -1; +*/ +int rte_thread_set_affinity (rte_cpuset_t *cpusetp); + +/** +* Get core affinity of the current thread. +* +* @param cpusetp +* Point to cpu_set_t for getting current thread cpu affinity. +* It presumes input is not NULL, otherwise it causes panic. +* +*/ +void rte_thread_get_affinity (rte_cpuset_t *cpusetp); + + #ifdef __cplusplus }#endif
lib/librte_eal/linuxapp/eal/eal_thread.c +2 -0
@@ -56,6 +56,8 @@#include "eal_thread.h" RTE_DEFINE_PER_LCORE (unsigned, _lcore_id); +RTE_DEFINE_PER_LCORE (unsigned, _socket_id); +RTE_DEFINE_PER_LCORE (rte_cpuset_t, _cpuset);/* * Send a message to a slave lcore identified by slave_id to call a
lib/librte_eal/linuxapp/eal/rte_eal_version.map +2 -0
@@ -82,6 +82,8 @@ DPDK_2.0 { rte_snprintf; rte_strerror; rte_strsplit; + rte_thread_get_affinity; + rte_thread_set_affinity; rte_vlog; rte_xen_dom0_memory_attach; rte_xen_dom0_memory_init;
Signature · 1 line
1.8.1.4
PATCH v8 7/19 eal: add eal_common_thread.c for common thread API
In reply to a message not in the archiveThe API works for both EAL thread and none EAL thread. When calling rte_thread_set_affinity, the *_socket_id* and *_cpuset* of calling thread will be updated if the thread successful set the cpu affinity.
---
v5 changes:
refine code of rte_thread_set_affinity() change rte_thread_get_affinity() return to void
lib/librte_eal/bsdapp/eal/Makefile | 1 + lib/librte_eal/common/eal_common_thread.c | 150 ++++++++++++++++++++++++++++++ lib/librte_eal/linuxapp/eal/Makefile | 2 + 3 files changed, 153 insertions(+) create mode 100644 lib/librte_eal/common/eal_common_thread.c
lib/librte_eal/bsdapp/eal/Makefile +1 -0
@@ -77,6 +77,7 @@ SRCS-$(CONFIG_RTE_LIBRTE_EAL_BSDAPP) += eal_common_hexdump.c SRCS-$(CONFIG_RTE_LIBRTE_EAL_BSDAPP) += eal_common_devargs.c SRCS-$(CONFIG_RTE_LIBRTE_EAL_BSDAPP) += eal_common_dev.c SRCS-$(CONFIG_RTE_LIBRTE_EAL_BSDAPP) += eal_common_options.c +SRCS-$(CONFIG_RTE_LIBRTE_EAL_BSDAPP) += eal_common_thread.c CFLAGS_eal.o := -D_GNU_SOURCE #CFLAGS_eal_thread.o := -D_GNU_SOURCE
lib/librte_eal/common/eal_common_thread.c new file +150 -0
150 lines not on this page · raw message
lib/librte_eal/linuxapp/eal/Makefile +2 -0
@@ -89,6 +89,7 @@ SRCS-$(CONFIG_RTE_LIBRTE_EAL_LINUXAPP) += eal_common_hexdump.c SRCS-$(CONFIG_RTE_LIBRTE_EAL_LINUXAPP) += eal_common_devargs.c SRCS-$(CONFIG_RTE_LIBRTE_EAL_LINUXAPP) += eal_common_dev.c SRCS-$(CONFIG_RTE_LIBRTE_EAL_LINUXAPP) += eal_common_options.c +SRCS-$(CONFIG_RTE_LIBRTE_EAL_LINUXAPP) += eal_common_thread.c CFLAGS_eal.o := -D_GNU_SOURCE CFLAGS_eal_lcore.o := -D_GNU_SOURCE
@@ -100,6 +101,7 @@ CFLAGS_eal_pci.o := -D_GNU_SOURCE CFLAGS_eal_pci_vfio.o := -D_GNU_SOURCE CFLAGS_eal_common_whitelist.o := -D_GNU_SOURCE CFLAGS_eal_common_options.o := -D_GNU_SOURCE +CFLAGS_eal_common_thread.o := -D_GNU_SOURCE # workaround for a gcc bug with noreturn attribute # http://gcc.gnu.org/bugzilla/show_bug.cgi?id=12603
Signature · 1 line
1.8.1.4
PATCH v8 8/19 eal: standardize init sequence between linux and bsd
In reply to a message not in the archive--- lib/librte_eal/bsdapp/eal/eal.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
lib/librte_eal/bsdapp/eal/eal.c +2 -2
@@ -509,6 +509,8 @@ rte_eal_init(int argc, char **argv)rte_eal_mcfg_complete (); +eal_thread_init_master (rte_config.master_lcore); +if (rte_eal_dev_init () <0 )rte_panic ("Cannot init pmd devices\n" );
@@ -532,8 +534,6 @@ rte_eal_init(int argc, char **argv)rte_panic ("Cannot create thread\n" ); } -eal_thread_init_master (rte_config.master_lcore); -/* * Launch a dummy function on all slave lcores, so that master lcore * knows they are all ready when this function returns.
Signature · 1 line
1.8.1.4
PATCH v8 9/19 eal: add rte_gettid() to acquire unique system tid
In reply to a message not in the archiveThe rte_gettid() wraps the linux and freebsd syscall gettid(). It provides a persistent unique thread id for the calling thread. It will save the unique id in TLS on the first time.
--- lib/librte_eal/bsdapp/eal/eal_thread.c | 9 +++++++++ lib/librte_eal/common/include/rte_eal.h | 27 +++++++++++++++++++++++++++ lib/librte_eal/linuxapp/eal/eal_thread.c | 7 +++++++ 3 files changed, 43 insertions(+)
lib/librte_eal/bsdapp/eal/eal_thread.c +9 -0
@@ -39,6 +39,7 @@#include <sched.h> #include <pthread_np.h> #include <sys/queue.h> +#include <sys/thr.h> #include <rte_debug.h> #include <rte_atomic.h>
@@ -233,3 +234,11 @@ eal_thread_loop(__attribute__((unused)) void *arg)/* pthread_exit(NULL); */ /* return NULL; */ } + +/* require calling thread tid by gettid() */ +int rte_sys_gettid (void ) +{ +long lwpid; +thr_self (&lwpid); +return (int )lwpid; +}
lib/librte_eal/common/include/rte_eal.h +27 -0
@@ -41,6 +41,9 @@*/ #include <stdint.h> +#include <sched.h> + +#include <rte_per_lcore.h> #ifdef __cplusplusextern "C" {
@@ -262,6 +265,30 @@ rte_set_application_usage_hook( rte_usage_hook_t usage_func );*/ int rte_eal_has_hugepages (void ); +/** +* A wrap API for syscall gettid. +* +* @return +* On success, returns the thread ID of calling process. +* It always successful. +*/ +int rte_sys_gettid (void ); + +/** +* Get system unique thread id. +* +* @return +* On success, returns the thread ID of calling process. +* It always successful. +*/ +static inline int rte_gettid (void ) +{ + static RTE_DEFINE_PER_LCORE(int, _thread_id) = -1; +if (RTE_PER_LCORE (_thread_id) ==-1 ) +RTE_PER_LCORE (_thread_id) =rte_sys_gettid (); +return RTE_PER_LCORE (_thread_id); +} + #ifdef __cplusplus }#endif
lib/librte_eal/linuxapp/eal/eal_thread.c +7 -0
@@ -39,6 +39,7 @@#include <pthread.h> #include <sched.h> #include <sys/queue.h> +#include <sys/syscall.h> #include <rte_debug.h> #include <rte_atomic.h>
@@ -233,3 +234,9 @@ eal_thread_loop(__attribute__((unused)) void *arg)/* pthread_exit(NULL); */ /* return NULL; */ } + +/* require calling thread tid by gettid() */ +int rte_sys_gettid (void ) +{ +return (int )syscall (SYS_gettid); +}
Signature · 1 line
1.8.1.4
PATCH v8 10/19 eal: apply affinity of EAL thread by assigned cpuset
In reply to a message not in the archiveEAL threads use assigned cpuset to set core affinity during startup. It keeps 1:1 mapping, if no '--lcores' option is used.
---
v5 changes:
add return check for dump_affinity
call rte_thread_set_affinity() directly during EAL thread set
lib/librte_eal/bsdapp/eal/eal.c | 10 +++-- lib/librte_eal/bsdapp/eal/eal_thread.c | 64 ++++++------------------------ lib/librte_eal/common/include/rte_lcore.h | 2 +- lib/librte_eal/linuxapp/eal/eal.c | 8 +++- lib/librte_eal/linuxapp/eal/eal_thread.c | 66 ++++++------------------------- 5 files changed, 37 insertions(+), 113 deletions(-)
lib/librte_eal/bsdapp/eal/eal.c +7 -3
@@ -432,6 +432,7 @@ rte_eal_init(int argc, char **argv)int i, fctret, ret;pthread_t thread_id;static rte_atomic32_t run_once =RTE_ATOMIC32_INIT (0 ); +char cpuset[RTE_CPU_AFFINITY_STR_LEN ];if (!rte_atomic32_test_and_set (&run_once))return -1 ;
@@ -502,15 +503,18 @@ rte_eal_init(int argc, char **argv)if (rte_eal_pci_init () <0 )rte_panic ("Cannot init PCI\n" ); -RTE_LOG (DEBUG ,EAL ,"Master core %u is ready (tid=%p)\n" , - rte_config.master_lcore, thread_id); -eal_check_mem_on_local_socket ();rte_eal_mcfg_complete ();eal_thread_init_master (rte_config.master_lcore); + ret =eal_thread_dump_affinity (cpuset,RTE_CPU_AFFINITY_STR_LEN ); + +RTE_LOG (DEBUG ,EAL ,"Master lcore %u is ready (tid=%p;cpuset=[%s%s])\n" , + rte_config.master_lcore, thread_id, cpuset, + ret ==0 ?"" :"..." ); +if (rte_eal_dev_init () <0 )rte_panic ("Cannot init pmd devices\n" );
lib/librte_eal/bsdapp/eal/eal_thread.c +11 -53
90 lines not on this page · raw message
lib/librte_eal/common/include/rte_lcore.h +1 -1
@@ -148,7 +148,7 @@ rte_lcore_index(int lcore_id)static inline unsigned rte_socket_id (void ) { -return lcore_config[rte_lcore_id ()].socket_id; +return RTE_PER_LCORE (_socket_id); }/**
lib/librte_eal/linuxapp/eal/eal.c +6 -2
@@ -702,6 +702,7 @@ rte_eal_init(int argc, char **argv)static rte_atomic32_t run_once =RTE_ATOMIC32_INIT (0 );struct shared_driver *solib =NULL ;const char *logid; +char cpuset[RTE_CPU_AFFINITY_STR_LEN ];if (!rte_atomic32_test_and_set (&run_once))return -1 ;
@@ -802,8 +803,11 @@ rte_eal_init(int argc, char **argv)eal_thread_init_master (rte_config.master_lcore); -RTE_LOG (DEBUG ,EAL ,"Master core %u is ready (tid=%x)\n" , - rte_config.master_lcore, (int )thread_id); + ret =eal_thread_dump_affinity (cpuset,RTE_CPU_AFFINITY_STR_LEN ); + +RTE_LOG (DEBUG ,EAL ,"Master lcore %u is ready (tid=%x;cpuset=[%s%s])\n" , + rte_config.master_lcore, (int )thread_id, cpuset, + ret ==0 ?"" :"..." );if (rte_eal_dev_init () <0 )rte_panic ("Cannot init pmd devices\n" );
lib/librte_eal/linuxapp/eal/eal_thread.c +12 -54
95 lines not on this page · raw message
Signature · 1 line
1.8.1.4
PATCH v8 11/19 enic: fix re-define freebsd compile complain
In reply to a message not in the archiveSome macro already been defined by freebsd 'sys/param.h'.
---
v5 changes:
rename the redefined MACRO instead of undefine them
lib/librte_pmd_enic/enic.h | 4 ++-- lib/librte_pmd_enic/enic_compat.h | 2 +- lib/librte_pmd_enic/vnic/vnic_dev.c | 6 +++--- 3 files changed, 6 insertions(+), 6 deletions(-)
lib/librte_pmd_enic/enic.h +2 -2
@@ -66,9 +66,9 @@#define ENIC_CALC_IP_CKSUM 1#define ENIC_CALC_TCP_UDP_CKSUM 2#define ENIC_MAX_MTU 9000 -#define PAGE_SIZE 4096 +#define ENIC_PAGE_SIZE 4096#define PAGE_ROUND_UP (x) \ - ((((unsigned long)(x)) + PAGE_SIZE-1) & (~(PAGE_SIZE-1))) + ((((unsigned long)(x)) + ENIC_PAGE_SIZE-1) & (~(ENIC_PAGE_SIZE-1)))#define ENICPMD_VFIO_PATH "/dev/vfio/vfio"/*#define ENIC_DESC_COUNT_MAKE_ODD (x) do{if ((~(x)) & 1) { (x)--; } }while(0)*/
lib/librte_pmd_enic/enic_compat.h +1 -1
@@ -67,7 +67,7 @@ #define pr_warn(y, args...) dev_warning(0, y, ##args)#define BUG () pr_err("BUG at %s:%d", __func__, __LINE__) -#define ALIGN (x, a) __ALIGN_MASK(x, (typeof(x))(a)-1) +#define VNIC_ALIGN (x, a) __ALIGN_MASK(x, (typeof(x))(a)-1)#define __ALIGN_MASK (x, mask) (((x)+(mask))&~(mask))#define udelay usleep#define DIV_ROUND_UP (n, d) (((n) + (d) - 1) / (d))
lib/librte_pmd_enic/vnic/vnic_dev.c +3 -3
@@ -242,9 +242,9 @@ unsigned int vnic_dev_desc_ring_size(struct vnic_dev_ring *ring,if (desc_count ==0 ) desc_count =4096 ; - ring->desc_count =ALIGN (desc_count, count_align); + ring->desc_count =VNIC_ALIGN (desc_count, count_align); - ring->desc_size =ALIGN (desc_size, desc_align); + ring->desc_size =VNIC_ALIGN (desc_size, desc_align); ring->size = ring->desc_count * ring->desc_size; ring->size_unaligned = ring->size + ring->base_align;
@@ -294,7 +294,7 @@ int vnic_dev_alloc_desc_ring(__attribute__((unused)) struct vnic_dev *vdev, ring->base_addr_unaligned = (dma_addr_t )rz->phys_addr; - ring->base_addr =ALIGN (ring->base_addr_unaligned, + ring->base_addr =VNIC_ALIGN (ring->base_addr_unaligned, ring->base_align); ring->descs = (u8 *)ring->descs_unaligned + (ring->base_addr - ring->base_addr_unaligned);
Signature · 1 line
1.8.1.4
PATCH v8 12/19 malloc: fix the issue of SOCKET_ID_ANY
In reply to a message not in the archiveAdd check for rte_socket_id(), avoid get unexpected return like (-1).
By using rte_malloc_socket(), socket id is assigned by socket_arg.
If socket_arg set to SOCKET_ID_ANY, it expects to use the socket id to which the current cores belongs. As the thread may affinity on a cpuset, the cores in the cpuset may belongs to different NUMA nodes. The value of _socket_id probably be SOCKET_ID_ANY(-1), the case is not expected in origin malloc_get_numa_socket().
---
v7 changes:
reword comments
lib/librte_malloc/malloc_heap.h | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)
lib/librte_malloc/malloc_heap.h +6 -1
@@ -44,7 +44,12 @@ extern "C" {static inline unsigned malloc_get_numa_socket (void ) { -return rte_socket_id (); +unsigned socket_id =rte_socket_id (); + +if (socket_id == (unsigned )SOCKET_ID_ANY ) +return 0 ; + +return socket_id; } void *
Signature · 1 line
1.8.1.4
PATCH v8 13/19 log: fix the gap to support non-EAL thread
In reply to a message not in the archiveFor those non-EAL thread, *_lcore_id* is invalid and probably larger than RTE_MAX_LCORE. The patch adds the check and allows only EAL thread using EAL per thread log level and log type. Others shares the global log level.
--- lib/librte_eal/common/eal_common_log.c | 17 +++++++++++++++-- lib/librte_eal/common/include/rte_log.h | 5 +++++ 2 files changed, 20 insertions(+), 2 deletions(-)
lib/librte_eal/common/eal_common_log.c +15 -2
@@ -193,11 +193,20 @@ rte_set_log_type(uint32_t type, int enable) rte_logs.type &= (~type); } +/* Get global log type */ +uint32_t +rte_get_log_type (void ) +{ +return rte_logs.type; +} +/* get the current loglevel for the message beeing processed */ int rte_log_cur_msg_loglevel (void ) {unsigned lcore_id; lcore_id =rte_lcore_id (); +if (lcore_id >=RTE_MAX_LCORE ) +return rte_get_log_level ();return log_cur_msg[lcore_id].loglevel; }
@@ -206,6 +215,8 @@ int rte_log_cur_msg_logtype(void) {unsigned lcore_id; lcore_id =rte_lcore_id (); +if (lcore_id >=RTE_MAX_LCORE ) +return rte_get_log_type ();return log_cur_msg[lcore_id].logtype; }
@@ -265,8 +276,10 @@ rte_vlog(__attribute__((unused)) uint32_t level,/* save loglevel and logtype in a global per-lcore variable */ lcore_id =rte_lcore_id (); - log_cur_msg[lcore_id].loglevel = level; - log_cur_msg[lcore_id].logtype = logtype; +if (lcore_id <RTE_MAX_LCORE ) { + log_cur_msg[lcore_id].loglevel = level; + log_cur_msg[lcore_id].logtype = logtype; + } ret =vfprintf (f, format, ap);fflush (f);
lib/librte_eal/common/include/rte_log.h +5 -0
@@ -144,6 +144,11 @@ uint32_t rte_get_log_level(void);void rte_set_log_type (uint32_t type,int enable);/** +* Get the global log type. +*/ +uint32_t rte_get_log_type (void ); + +/** * Get the current loglevel for the message being processed. * * Before calling the user-defined stream for logging, the log
Signature · 1 line
1.8.1.4
PATCH v8 14/19 eal: set _lcore_id and _socket_id to (-1) by default
In reply to a message not in the archiveFor those none EAL thread, *_lcore_id* shall always be LCORE_ID_ANY. The libraries using *_lcore_id* as index need to take care. *_socket_id* always be SOCKET_ID_ANY unitl the thread changes the affinity by rte_thread_set_affinity()
---
v5 changes:
define LCORE_ID_ANY as UINT32_MAX
lib/librte_eal/bsdapp/eal/eal_thread.c | 4 ++-- lib/librte_eal/common/include/rte_lcore.h | 4 ++-- lib/librte_eal/linuxapp/eal/eal_thread.c | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-)
lib/librte_eal/bsdapp/eal/eal_thread.c +2 -2
@@ -56,8 +56,8 @@#include "eal_private.h" #include "eal_thread.h" -RTE_DEFINE_PER_LCORE (unsigned, _lcore_id); -RTE_DEFINE_PER_LCORE (unsigned, _socket_id); +RTE_DEFINE_PER_LCORE (unsigned, _lcore_id) =LCORE_ID_ANY ; +RTE_DEFINE_PER_LCORE (unsigned, _socket_id) = (unsigned )SOCKET_ID_ANY ;RTE_DEFINE_PER_LCORE (rte_cpuset_t, _cpuset);/*
lib/librte_eal/common/include/rte_lcore.h +2 -2
@@ -48,7 +48,7 @@extern "C" {#endif -#define LCORE_ID_ANY -1/**< Any lcore. */ +#define LCORE_ID_ANY UINT32_MAX/**< Any lcore. */ #if defined(__linux__)typedef cpu_set_t rte_cpuset_t ;
@@ -87,7 +87,7 @@ RTE_DECLARE_PER_LCORE(rte_cpuset_t, _cpuset); /**< Per thread "cpuset". *//** * Return the ID of the execution unit we are running on. * @return -* Logical core ID +* Logical core ID(in EAL thread) or LCORE_ID_ANY(in non-EAL thread) */ static inline unsigned rte_lcore_id (void )
lib/librte_eal/linuxapp/eal/eal_thread.c +2 -2
@@ -56,8 +56,8 @@#include "eal_private.h" #include "eal_thread.h" -RTE_DEFINE_PER_LCORE (unsigned, _lcore_id); -RTE_DEFINE_PER_LCORE (unsigned, _socket_id); +RTE_DEFINE_PER_LCORE (unsigned, _lcore_id) =LCORE_ID_ANY ; +RTE_DEFINE_PER_LCORE (unsigned, _socket_id) = (unsigned )SOCKET_ID_ANY ;RTE_DEFINE_PER_LCORE (rte_cpuset_t, _cpuset);/*
Signature · 1 line
1.8.1.4
PATCH v8 15/19 eal: fix recursive spinlock in non-EAL thraed
In reply to a message not in the archiveIn non-EAL thread, lcore_id alrways be LCORE_ID_ANY. It cann't be used as unique id for recursive spinlock. Then use rte_gettid() to replace it.
--- lib/librte_eal/common/include/generic/rte_spinlock.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
lib/librte_eal/common/include/generic/rte_spinlock.h +2 -2
@@ -179,7 +179,7 @@ static inline void rte_spinlock_recursive_init(rte_spinlock_recursive_t *slr)*/ static inline void rte_spinlock_recursive_lock (rte_spinlock_recursive_t *slr) { -int id =rte_lcore_id (); +int id =rte_gettid ();if (slr->user != id) {rte_spinlock_lock (&slr->sl);
@@ -212,7 +212,7 @@ static inline void rte_spinlock_recursive_unlock(rte_spinlock_recursive_t *slr)*/ static inline int rte_spinlock_recursive_trylock (rte_spinlock_recursive_t *slr) { -int id =rte_lcore_id (); +int id =rte_gettid ();if (slr->user != id) {if (rte_spinlock_trylock (&slr->sl) ==0 )
Signature · 1 line
1.8.1.4
PATCH v8 16/19 mempool: add support to non-EAL thread
In reply to a message not in the archiveFor non-EAL thread, bypass per lcore cache, directly use ring pool. It allows using rte_mempool in either EAL thread or any user pthread. As in non-EAL thread, it directly rely on rte_ring and it's none preemptive. It doesn't suggest to run multi-pthread/cpu which compete the rte_mempool. It will get bad performance and has critical risk if scheduling policy is RT. Haven't found significant performance decrease by mempool_perf_test.
---
v6 changes:
rollback v5 changes
v5 changes:
check __lcore_id with LCORE_ID_ANY instead of RTE_MAX_LCORE
lib/librte_mempool/rte_mempool.h | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-)
lib/librte_mempool/rte_mempool.h +11 -7
@@ -198,10 +198,12 @@ struct rte_mempool {* Number to add to the object-oriented statistics. */ #ifdef RTE_LIBRTE_MEMPOOL_DEBUG -#define __MEMPOOL_STAT_ADD (mp, name, n) do { \ - unsigned __lcore_id = rte_lcore_id(); \ - mp->stats[__lcore_id].name##_objs += n; \ - mp->stats[__lcore_id].name##_bulk += 1; \ +#define __MEMPOOL_STAT_ADD (mp, name, n) do { \ + unsigned __lcore_id = rte_lcore_id(); \ + if (__lcore_id < RTE_MAX_LCORE) { \ + mp->stats[__lcore_id].name##_objs += n; \ + mp->stats[__lcore_id].name##_bulk += 1; \ + } \ } while(0)#else #define __MEMPOOL_STAT_ADD (mp, name, n) do {} while(0)
@@ -767,8 +769,9 @@ __mempool_put_bulk(struct rte_mempool *mp, void * const *obj_table,__MEMPOOL_STAT_ADD (mp, put, n);#if RTE_MEMPOOL_CACHE_MAX_SIZE >0 -/* cache is not enabled or single producer */ -if (unlikely (cache_size ==0 || is_mp ==0 )) +/* cache is not enabled or single producer or none EAL thread */ +if (unlikely (cache_size ==0 || is_mp ==0 || + lcore_id >=RTE_MAX_LCORE )) goto ring_enqueue;/* Go straight to ring if put would overflow mem allocated for cache */
@@ -952,7 +955,8 @@ __mempool_get_bulk(struct rte_mempool *mp, void **obj_table,uint32_t cache_size = mp->cache_size;/* cache is not enabled or single consumer */ -if (unlikely (cache_size ==0 || is_mc ==0 || n >= cache_size)) +if (unlikely (cache_size ==0 || is_mc ==0 || + n >= cache_size || lcore_id >=RTE_MAX_LCORE )) goto ring_dequeue; cache = &mp->local_cache[lcore_id];
Signature · 1 line
1.8.1.4
PATCH v8 17/19 ring: add support to non-EAL thread
In reply to a message not in the archivering debug stat won't take care non-EAL thread.
---
v6 changes:
rollback v5 changes
v5 changes:
check __lcore_id with LCORE_ID_ANY instead of RTE_MAX_LCORE
lib/librte_ring/rte_ring.h | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-)
lib/librte_ring/rte_ring.h +6 -4
@@ -188,10 +188,12 @@ struct rte_ring {* The number to add to the object-oriented statistics. */ #ifdef RTE_LIBRTE_RING_DEBUG -#define __RING_STAT_ADD (r, name, n) do { \ - unsigned __lcore_id = rte_lcore_id(); \ - r->stats[__lcore_id].name##_objs += n; \ - r->stats[__lcore_id].name##_bulk += 1; \ +#define __RING_STAT_ADD (r, name, n) do { \ + unsigned __lcore_id = rte_lcore_id(); \ + if (__lcore_id < RTE_MAX_LCORE) { \ + r->stats[__lcore_id].name##_objs += n; \ + r->stats[__lcore_id].name##_bulk += 1; \ + } \ } while(0)#else #define __RING_STAT_ADD (r, name, n) do {} while(0)
Signature · 1 line
1.8.1.4
PATCH v8 18/19 ring: add sched_yield to avoid spin forever
In reply to a message not in the archiveAdd a sched_yield() syscall if the thread spins for too long, waiting other thread to finish its operations on the ring. That gives pre-empted thread a chance to proceed and finish with ring enqnue/dequeue operation.
The purpose is to reduce contention on the ring. By ring_perf_test, it doesn't shows additional perf penalty.
---
v6 changes:
rename RTE_RING_PAUSE_REP to RTE_RING_PAUSE_REP_COUNT set default value as '0' in configure file
v5 changes:
add RTE_RING_PAUSE_REP to config file
v4 changes:
update and add more comments on sched_yield()
v3 changes:
new patch adding sched_yield() in rte_ring to avoid long spin
config/common_bsdapp | 1 + config/common_linuxapp | 1 + lib/librte_ring/rte_ring.h | 31 +++++++++++++++++++++++++++---- 3 files changed, 29 insertions(+), 4 deletions(-)
config/common_bsdapp +1 -0
@@ -234,6 +234,7 @@ CONFIG_RTE_PMD_PACKET_PREFETCH=y CONFIG_RTE_LIBRTE_RING=y CONFIG_RTE_LIBRTE_RING_DEBUG=n CONFIG_RTE_RING_SPLIT_PROD_CONS=n +CONFIG_RTE_RING_PAUSE_REP_COUNT=0 # # Compile librte_mempool
config/common_linuxapp +1 -0
@@ -242,6 +242,7 @@ CONFIG_RTE_PMD_PACKET_PREFETCH=y CONFIG_RTE_LIBRTE_RING=y CONFIG_RTE_LIBRTE_RING_DEBUG=n CONFIG_RTE_RING_SPLIT_PROD_CONS=n +CONFIG_RTE_RING_PAUSE_REP_COUNT=0 # # Compile librte_mempool
lib/librte_ring/rte_ring.h +27 -4
@@ -127,6 +127,11 @@ struct rte_ring_debug_stats {#define RTE_RING_NAMESIZE 32/**< The maximum length of a ring name. */ #define RTE_RING_MZ_PREFIX "RG_" +#ifndef RTE_RING_PAUSE_REP_COUNT +#define RTE_RING_PAUSE_REP_COUNT 0/**< yield after pause num of times, no yield +* if RTE_RING_PAUSE_REP not defined. */ +#endif +/** * An RTE ring structure. *
@@ -410,7 +415,7 @@ __rte_ring_mp_do_enqueue(struct rte_ring *r, void * const *obj_table,uint32_t cons_tail, free_entries;const unsigned max = n;int success; -unsigned i; +unsigned i, rep =0 ;uint32_t mask = r->prod.mask;int ret;
@@ -468,9 +473,18 @@ __rte_ring_mp_do_enqueue(struct rte_ring *r, void * const *obj_table,* If there are other enqueues in progress that preceded us, * we need to wait for them to complete */ -while (unlikely (r->prod.tail != prod_head)) +while (unlikely (r->prod.tail != prod_head)) {rte_pause (); +/* Set RTE_RING_PAUSE_REP_COUNT to avoid spin too long waiting +* for other thread finish. It gives pre-empted thread a chance +* to proceed and finish with ring denqnue operation. */ +if (RTE_RING_PAUSE_REP_COUNT && + ++rep ==RTE_RING_PAUSE_REP_COUNT ) { + rep =0 ; +sched_yield (); + } + } r->prod.tail = prod_next;return ret; }
@@ -589,7 +603,7 @@ __rte_ring_mc_do_dequeue(struct rte_ring *r, void **obj_table,uint32_t cons_next, entries;const unsigned max = n;int success; -unsigned i; +unsigned i, rep =0 ;uint32_t mask = r->prod.mask;/* move cons.head atomically */
@@ -634,9 +648,18 @@ __rte_ring_mc_do_dequeue(struct rte_ring *r, void **obj_table,* If there are other dequeues in progress that preceded us, * we need to wait for them to complete */ -while (unlikely (r->cons.tail != cons_head)) +while (unlikely (r->cons.tail != cons_head)) {rte_pause (); +/* Set RTE_RING_PAUSE_REP_COUNT to avoid spin too long waiting +* for other thread finish. It gives pre-empted thread a chance +* to proceed and finish with ring denqnue operation. */ +if (RTE_RING_PAUSE_REP_COUNT && + ++rep ==RTE_RING_PAUSE_REP_COUNT ) { + rep =0 ; +sched_yield (); + } + }__RING_STAT_ADD (r, deq_success, n); r->cons.tail = cons_next;
Signature · 1 line
1.8.1.4
PATCH v8 19/19 timer: add support to non-EAL thread
In reply to a message not in the archiveAllow to setup timers only for EAL (lcore) threads (__lcore_id < MAX_LCORE_ID). E.g. – dynamically created thread will be able to reset/stop timer for lcore thread, but it will be not allowed to setup timer for itself or another non-lcore thread. rte_timer_manage() for non-lcore thread would simply do nothing and return straightway.
---
v6 changes:
use 'RTE_MAX_LCORE' to check the EAL thread with valid lcore_id. use 'LCORE_ID_ANY' for any unspecified lcore_id assignment.
v5 changes:
add assert in rte_timer_manage
remove duplicate check in timer_set_config_state
lib/librte_timer/rte_timer.c | 32 +++++++++++++++++++++++--------- lib/librte_timer/rte_timer.h | 4 ++-- 2 files changed, 25 insertions(+), 11 deletions(-)
lib/librte_timer/rte_timer.c +23 -9
@@ -35,6 +35,7 @@#include <stdio.h> #include <stdint.h> #include <inttypes.h> +#include <assert.h> #include <rte_atomic.h> #include <rte_common.h>
@@ -79,9 +80,10 @@ static struct priv_timer priv_timer[RTE_MAX_LCORE];/* when debug is enabled, store some statistics */ #ifdef RTE_LIBRTE_TIMER_DEBUG -#define __TIMER_STAT_ADD (name, n) do { \ - unsigned __lcore_id = rte_lcore_id(); \ - priv_timer[__lcore_id].stats.name += (n); \ +#define __TIMER_STAT_ADD (name, n) do { \ + unsigned __lcore_id = rte_lcore_id(); \ + if (__lcore_id < RTE_MAX_LCORE) \ + priv_timer[__lcore_id].stats.name += (n); \ } while(0)#else #define __TIMER_STAT_ADD (name, n) do {} while(0)
@@ -135,7 +137,7 @@ timer_set_config_state(struct rte_timer *tim,/* timer is running on another core, exit */ if (prev_status.state ==RTE_TIMER_RUNNING && - (unsigned )prev_status.owner != lcore_id) + prev_status.owner != (uint16_t )lcore_id)return -1 ;/* timer is being configured on another core */
@@ -366,9 +368,16 @@ __rte_timer_reset(struct rte_timer *tim, uint64_t expire,/* round robin for tim_lcore */ if (tim_lcore == (unsigned )LCORE_ID_ANY ) { - tim_lcore =rte_get_next_lcore (priv_timer[lcore_id].prev_lcore, -0 ,1 ); - priv_timer[lcore_id].prev_lcore = tim_lcore; +if (lcore_id <RTE_MAX_LCORE ) { +/* EAL thread with valid lcore_id */ + tim_lcore =rte_get_next_lcore ( + priv_timer[lcore_id].prev_lcore, +0 ,1 ); + priv_timer[lcore_id].prev_lcore = tim_lcore; + }else +/* non-EAL thread do not run rte_timer_manage(), +* so schedule the timer on the first enabled lcore. */ + tim_lcore =rte_get_next_lcore (LCORE_ID_ANY ,0 ,1 ); }/* wait that the timer is in correct status before update,
@@ -378,7 +387,8 @@ __rte_timer_reset(struct rte_timer *tim, uint64_t expire,return -1 ;__TIMER_STAT_ADD (reset,1 ); -if (prev_status.state ==RTE_TIMER_RUNNING ) { +if (prev_status.state ==RTE_TIMER_RUNNING && + lcore_id <RTE_MAX_LCORE ) { priv_timer[lcore_id].updated =1 ; }
@@ -455,7 +465,8 @@ rte_timer_stop(struct rte_timer *tim)return -1 ;__TIMER_STAT_ADD (stop,1 ); -if (prev_status.state ==RTE_TIMER_RUNNING ) { +if (prev_status.state ==RTE_TIMER_RUNNING && + lcore_id <RTE_MAX_LCORE ) { priv_timer[lcore_id].updated =1 ; }
@@ -499,6 +510,9 @@ void rte_timer_manage(void)uint64_t cur_time;int i, ret; +/* timer manager only runs on EAL thread with valid lcore_id */ +assert (lcore_id <RTE_MAX_LCORE ); +__TIMER_STAT_ADD (manage,1 );/* optimize for the case where per-cpu list is empty */ if (priv_timer[lcore_id].pending_head.sl_next[0 ] ==NULL )
lib/librte_timer/rte_timer.h +2 -2
@@ -76,7 +76,7 @@ extern "C" {#define RTE_TIMER_RUNNING 2/**< State: timer function is running. */ #define RTE_TIMER_CONFIG 3/**< State: timer is being configured. */ -#define RTE_TIMER_NO_OWNER -1/**< Timer has no owner. */ +#define RTE_TIMER_NO_OWNER -2/**< Timer has no owner. */ /** * Timer type: Periodic or single (one-shot).
@@ -310,7 +310,7 @@ int rte_timer_pending(struct rte_timer *tim);/** * Manage the timer list and execute callback functions. * -* This function must be called periodically from all cores +* This function must be called periodically from EAL lcores * main_loop(). It browses the list of pending timers and runs all * timers that are expired. *
Signature · 1 line
1.8.1.4
Ananyev, Konstantin
Acked-by Konstantin AnanyevQuoted 93 lines
-----Original Message-----
From: Liang, Cunming
Sent: Tuesday, February 17, 2015 2:08 AM
To: [email protected]
Cc: Ananyev, Konstantin; [email protected]; [email protected]; [email protected]; Liang, Cunming
Subject: [PATCH v8 00/19] support multi-pthread per corev8 changes:
keep using strlen for trusted input stringv7 changes:
update EAL version map for new public EAL API rollback to usestrnlen()passing EAL core optionv6 changes:
renameRTE_RING_PAUSE_REP(_COUNT)and set default to 0 rollback to useRTE_MAX_LCOREwhen checking validlcore_idfor EAL threadv5 changes:
reorder some patch and split into addtional two patchesrte_thread_get_affinity()return type change to avoid addRTE_RING_PAUSE_REPinto config and by default turn offv4 changes:
new patch fixingstrnlen()invalid return in 32bit icc [03/17] update and add more comments onsched_yield()[16/17]v3 changes:
new patch addingsched_yield()inrte_ringto avoid long spin [16/17]v2 changes:
add '<number>-<number>' support for EAL option '--lcores' [02/17]The patch series contain the enhancements of EAL and fixes for libraries
to run multi-pthreads(either EAL or non-EAL thread) per physical core.
Two major changes list as below:
- Extend the core affinity of each EAL thread to 1:n.
Each lcore stands for a EAL thread rather than a logical core.
The change adds new EAL option to allow static lcore to cpuset assginment. Then a lcore(EAL thread) affinity to a cpuset, original 1:1 mapping is the special case.
- Fix the libraries to allow running on any non-EAL thread.
It fix the gaps running libraries in non-EAL thread(dynamic created by user). Each fix libraries take care the case ofrte_lcore_id()>=RTE_MAX_LCORE.Thanks a million for the comments from Konstantin, Bruce, Mirek and Stephen in RFC review.
Cunming Liang (19):
eal: add cpuset into per EAL threadlcore_config
eal: fixPAGE_SIZEredefine complaint on freebsd
eal: new eal option '--lcores' for cpu assignment
eal: fix wrongstrnlen()return value in 32bit icc
eal: add public function parsingsocket_idfromcpu_id
eal: new TLS definition and API declaration
eal: addeal_common_thread.cfor common thread API
eal: standardize init sequence between linux and bsd
eal: addrte_gettid()to acquire unique system tid
eal: apply affinity of EAL thread by assigned cpuset
enic: fix re-define freebsd compile complain
malloc: fix the issue ofSOCKET_ID_ANY
log: fix the gap to support non-EAL thread
eal: set_lcore_idand_socket_idto (-1) by default
eal: fix recursive spinlock in non-EAL thraed
mempool: add support to non-EAL thread
ring: add support to non-EAL thread
ring: addsched_yieldto avoid spin forever
timer: add support to non-EAL threadconfig/common_bsdapp | 1 + config/common_linuxapp | 1 + lib/librte_eal/bsdapp/eal/Makefile | 1 + lib/librte_eal/bsdapp/eal/eal.c | 14 +- lib/librte_eal/bsdapp/eal/eal_lcore.c | 14 + lib/librte_eal/bsdapp/eal/eal_memory.c | 8 +- lib/librte_eal/bsdapp/eal/eal_thread.c | 77 ++---- lib/librte_eal/bsdapp/eal/rte_eal_version.map | 2 + lib/librte_eal/common/eal_common_log.c | 17 +- lib/librte_eal/common/eal_common_options.c | 308 ++++++++++++++++++++- lib/librte_eal/common/eal_common_thread.c | 150 ++++++++++ lib/librte_eal/common/eal_options.h | 2 + lib/librte_eal/common/eal_thread.h | 47 ++++ .../common/include/generic/rte_spinlock.h | 4 +- lib/librte_eal/common/include/rte_eal.h | 27 ++ lib/librte_eal/common/include/rte_lcore.h | 40 ++- lib/librte_eal/common/include/rte_log.h | 5 + lib/librte_eal/linuxapp/eal/Makefile | 4 + lib/librte_eal/linuxapp/eal/eal.c | 8 +- lib/librte_eal/linuxapp/eal/eal_lcore.c | 15 +- lib/librte_eal/linuxapp/eal/eal_thread.c | 77 ++---- lib/librte_eal/linuxapp/eal/rte_eal_version.map | 2 + lib/librte_malloc/malloc_heap.h | 7 +- lib/librte_mempool/rte_mempool.h | 18 +-
Quoted 9 lines
lib/librte_pmd_enic/enic.h | 4 +- lib/librte_pmd_enic/enic_compat.h | 2 +- lib/librte_pmd_enic/vnic/vnic_dev.c | 6 +- lib/librte_ring/rte_ring.h | 41 ++- lib/librte_timer/rte_timer.c | 32 ++- lib/librte_timer/rte_timer.h | 4 +- 30 files changed, 769 insertions(+), 169 deletions(-) create mode 100644 lib/librte_eal/common/eal_common_thread.c
Quoted 2 lines
--
1.8.1.4
A message that is not in the archive (sent off-list or not yet received): 2601191342CEEE43887BDE71AB977258213EE0A9-pww93C2UFcwu0RiL9chJVbfspsVTdybXVpNB7YpNyf8@public.gmane.org
Thomas Monjalon
AppliedQuoted 60 lines
Quoted 51 lines
v8 changes:
keep using strlen for trusted input stringv7 changes:
update EAL version map for new public EAL API rollback to usestrnlen()passing EAL core optionv6 changes:
renameRTE_RING_PAUSE_REP(_COUNT)and set default to 0 rollback to useRTE_MAX_LCOREwhen checking validlcore_idfor EAL threadv5 changes:
reorder some patch and split into addtional two patchesrte_thread_get_affinity()return type change to avoid addRTE_RING_PAUSE_REPinto config and by default turn offv4 changes:
new patch fixingstrnlen()invalid return in 32bit icc [03/17] update and add more comments onsched_yield()[16/17]v3 changes:
new patch addingsched_yield()inrte_ringto avoid long spin [16/17]v2 changes:
add '<number>-<number>' support for EAL option '--lcores' [02/17]The patch series contain the enhancements of EAL and fixes for libraries
to run multi-pthreads(either EAL or non-EAL thread) per physical core.
Two major changes list as below:
- Extend the core affinity of each EAL thread to 1:n.
Each lcore stands for a EAL thread rather than a logical core.
The change adds new EAL option to allow static lcore to cpuset assginment. Then a lcore(EAL thread) affinity to a cpuset, original 1:1 mapping is the special case.
- Fix the libraries to allow running on any non-EAL thread.
It fix the gaps running libraries in non-EAL thread(dynamic created by user). Each fix libraries take care the case ofrte_lcore_id()>=RTE_MAX_LCORE.Thanks a million for the comments from Konstantin, Bruce, Mirek and Stephen in RFC review.
Cunming Liang (19):
eal: add cpuset into per EAL threadlcore_config
eal: fixPAGE_SIZEredefine complaint on freebsd
eal: new eal option '--lcores' for cpu assignment
eal: fix wrongstrnlen()return value in 32bit icc
eal: add public function parsingsocket_idfromcpu_id
eal: new TLS definition and API declaration
eal: addeal_common_thread.cfor common thread API
eal: standardize init sequence between linux and bsd
eal: addrte_gettid()to acquire unique system tid
eal: apply affinity of EAL thread by assigned cpuset
enic: fix re-define freebsd compile complainQuoted 8 lines
malloc: fix the issue of
SOCKET_ID_ANY
log: fix the gap to support non-EAL thread
eal: set_lcore_idand_socket_idto (-1) by default
eal: fix recursive spinlock in non-EAL thraed
mempool: add support to non-EAL thread
ring: add support to non-EAL thread
ring: addsched_yieldto avoid spin forever
timer: add support to non-EAL thread
Quoted 1 line
I tried to fix many english typos. Please consider it during reviews. Cunming, you'll repeat 10 times "non-EAL threads compute more than none" ;)
Applied, thanks
My main concern in this patchset is about naming. Now lcore means thread in many places. I would prefer to have a cleanup to use right term at right place, even if it requires breaking API.
Are we going to deprecate the fresh option -l in favor of --lcores/--threads?
Quoted 72 lines
-----Original Message-----
From: Thomas Monjalon [mailto:[email protected]]
Sent: Wednesday, February 25, 2015 2:53 AM
To: Liang, Cunming
Cc: Ananyev, Konstantin; [email protected]; [email protected]; [email protected]
Subject: Re: [PATCH v8 00/19] support multi-pthread per coreQuoted 26 lines
Quoted 26 lines
v8 changes:
keep using strlen for trusted input stringv7 changes:
update EAL version map for new public EAL API rollback to usestrnlen()passing EAL core optionv6 changes:
renameRTE_RING_PAUSE_REP(_COUNT)and set default to 0 rollback to useRTE_MAX_LCOREwhen checking validlcore_idfor EAL threadv5 changes:
reorder some patch and split into addtional two patchesrte_thread_get_affinity()return type change to avoid addRTE_RING_PAUSE_REPinto config and by default turn offv4 changes:
new patch fixingstrnlen()invalid return in 32bit icc [03/17] update and add more comments onsched_yield()[16/17]v3 changes:
new patch addingsched_yield()inrte_ringto avoid long spin [16/17]v2 changes:
add '<number>-<number>' support for EAL option '--lcores' [02/17]Quoted 7 lines
Quoted 7 lines
The patch series contain the enhancements of EAL and fixes for libraries to run multi-pthreads(either EAL or non-EAL thread) per physical core. Two major changes list as below:
- Extend the core affinity of each EAL thread to 1:n.
Each lcore stands for a EAL thread rather than a logical core. The change adds new EAL option to allow static lcore to cpuset assginment. Then a lcore(EAL thread) affinity to a cpuset, original 1:1 mapping is thespecial case.
Quoted 5 lines
Quoted 5 lines
- Fix the libraries to allow running on any non-EAL thread.
It fix the gaps running libraries in non-EAL thread(dynamic created by user). Each fix libraries take care the case ofrte_lcore_id()>=RTE_MAX_LCORE.Thanks a million for the comments from Konstantin, Bruce, Mirek and
Stephen in RFC review.
Quoted 22 lines
Quoted 21 lines
Cunming Liang (19):
eal: add cpuset into per EAL threadlcore_config
eal: fixPAGE_SIZEredefine complaint on freebsd
eal: new eal option '--lcores' for cpu assignment
eal: fix wrongstrnlen()return value in 32bit icc
eal: add public function parsingsocket_idfromcpu_id
eal: new TLS definition and API declaration
eal: addeal_common_thread.cfor common thread API
eal: standardize init sequence between linux and bsd
eal: addrte_gettid()to acquire unique system tid
eal: apply affinity of EAL thread by assigned cpuset
enic: fix re-define freebsd compile complain
malloc: fix the issue ofSOCKET_ID_ANY
log: fix the gap to support non-EAL thread
eal: set_lcore_idand_socket_idto (-1) by default
eal: fix recursive spinlock in non-EAL thraed
mempool: add support to non-EAL thread
ring: add support to non-EAL thread
ring: addsched_yieldto avoid spin forever
timer: add support to non-EAL thread
Quoted 6 lines
Quoted 1 line
I tried to fix many english typos. Please consider it during reviews. Cunming, you'll repeat 10 times "non-EAL threads compute more than none" ;)
Applied, thanks
[Liang, Cunming] Thanks, Thomas. I'll take care of it next time. :)
Quoted 4 lines
My main concern in this patchset is about naming. Now lcore means thread in many places. I would prefer to have a cleanup to use right term at right place, even if it requires breaking API.
[Liang, Cunming] 'lcore' is limited used as EAL thread.
Comparing to the legacy usage, the difference is such lcore(logical core) may not only affinity to one physical core.
If extending the meaning of 'lcore' a bit wider (as prog_guide doc said, let's consider a logical core stands for an EAL thread), it then makes sense to keep origin APIs. That helps the existing apps migrate transparently.
Quoted 2 lines
Are we going to deprecate the fresh option -l in favor of --lcores/--threads?
[Liang, Cunming] I think so, as '--lcores' already covered '-l' pattern. Mark it as deprecated, and remove it on next version ?
Wan, Qun
Tested-by qun.wanPatch name: [PATCH v7 00/19] support multi-pthread per core
Test Flag: Tested-by
Tester name: [email protected]
Result summary: total 46 cases, 46 passed, 0 failed
OS Environment: Linux Fedora 20 3.17.8-200.fc20.x86_64/FreeBSD10
Gcc: gcc version 4.8.3 20140911
CPU: Intel(R) Xeon(R) CPU E5-2680 v2 @ 2.80GHz
NIC: Intel Corporation 82599ES 10-Gigabit SFI/SFP+ Network Connection
Test Result: PASSED
Detail: Command line test including positive test and negative test
x86_64-native-linuxapp-gcc
Niantic
./x86_64-native-linuxapp-gcc/app/testpmd --lcores='0@8,(4-5)@(8-11)' -n 4 -- -i --txfreet=32 --rxfreet=32 --txqflags=0xf01 --txrst=32
./x86_64-native-linuxapp-gcc/app/testpmd --lcores='1,2@(0-4,6),(3-4,6)@5,(7,8)' -n 4 -- -i --txfreet=32 --rxfreet=32 --txqflags=0xf01 --txrst=32
./x86_64-native-linuxapp-gcc/app/testpmd --lcores='(0,127)@(4,5)' -n 4 -- -i --txfreet=32 --rxfreet=32 --txqflags=0xf01 --txrst=32
./x86_64-native-linuxapp-gcc/app/testpmd --lcores='2-5,6,7-9' -n 4 -- -i --txfreet=32 --rxfreet=32 --txqflags=0xf01 --txrst=32
./x86_64-native-linuxapp-gcc/app/testpmd --lcores='2, (3-5)@ 3' -n 4 -- -i --txfreet=32 --rxfreet=32 --txqflags=0xf01 --txrst=32
./x86_64-native-linuxapp-gcc/app/testpmd --lcores='(0,64-66)@(4,5)' -n 4 -- -i --txfreet=32 --rxfreet=32 --txqflags=0xf01 --txrst=32
./x86_64-native-linuxapp-gcc/app/testpmd --lcores='(0,7-4)@(4,5)' -n 4 -- -i --txfreet=32 --rxfreet=32 --txqflags=0xf01 --txrst=32
./x86_64-native-linuxapp-gcc/app/testpmd --lcores='(0-,4-7)@(4,5)' -n 4 -- -i --txfreet=32 --rxfreet=32 --txqflags=0xf01 --txrst=32
./x86_64-native-linuxapp-gcc/app/testpmd --lcores='(-1,4-7)@(4,5)' -n 4 -- -i --txfreet=32 --rxfreet=32 --txqflags=0xf01 --txrst=32
./x86_64-native-linuxapp-gcc/app/testpmd --lcores='(0,4-7-9)@(4,5)' -n 4 -- -i --txfreet=32 --rxfreet=32 --txqflags=0xf01 --txrst=32
./x86_64-native-linuxapp-gcc/app/testpmd --lcores='(0,abcd)@(4,5)' -n 4 -- -i --txfreet=32 --rxfreet=32 --txqflags=0xf01 --txrst=32
./x86_64-native-linuxapp-gcc/app/testpmd --lcores='(0,4-7)@(1-,5)' -n 4 -- -i --txfreet=32 --rxfreet=32 --txqflags=0xf01 --txrst=32
./x86_64-native-linuxapp-gcc/app/testpmd --lcores='(0,4-7)@(-1,5)' -n 4 -- -i --txfreet=32 --rxfreet=32 --txqflags=0xf01 --txrst=32
./x86_64-native-linuxapp-gcc/app/testpmd --lcores='(0,4-7)@(4,5-8-9)' -n 4 -- -i --txfreet=32 --rxfreet=32 --txqflags=0xf01 --txrst=32
./x86_64-native-linuxapp-gcc/app/testpmd --lcores='(0,4-7)@(abc,5)' -n 4 -- -i --txfreet=32 --rxfreet=32 --txqflags=0xf01 --txrst=32
./x86_64-native-linuxapp-gcc/app/testpmd --lcores='(0,4-7)@(4,xyz)' -n 4 -- -i --txfreet=32 --rxfreet=32 --txqflags=0xf01 --txrst=32
./x86_64-native-linuxapp-gcc/app/testpmd --lcores='(0,4-7)=(8,9)' -n 4 -- -i --txfreet=32 --rxfreet=32 --txqflags=0xf01 --txrst=32
./x86_64-native-linuxapp-gcc/app/testpmd --lcores='2,3@4,(0-1,,4))' -n 4 -- -i --txfreet=32 --rxfreet=32 --txqflags=0xf01 --txrst=32
./x86_64-native-linuxapp-gcc/app/testpmd --lcores='[0-,4-7]@(4,5)' -n 4 -- -i --txfreet=32 --rxfreet=32 --txqflags=0xf01 --txrst=32
./x86_64-native-linuxapp-gcc/app/testpmd --lcores='(0-,4-7)@[4,5]' -n 4 -- -i --txfreet=32 --rxfreet=32 --txqflags=0xf01 --txrst=32
./x86_64-native-linuxapp-gcc/app/testpmd --lcores='3-4@3,2@5-6' -n 4 -- -i --txfreet=32 --rxfreet=32 --txqflags=0xf01 --txrst=32
./x86_64-native-linuxapp-gcc/app/testpmd --lcores='2,,3''2--3' -n 4 -- -i --txfreet=32 --rxfreet=32 --txqflags=0xf01 --txrst=32
./x86_64-native-linuxapp-gcc/app/testpmd --lcores='2,,,3''2--3' -n 4 -- -i --txfreet=32 --rxfreet=32 --txqflags=0xf01 --txrst=32
x86_64-native-bsdapp-gcc
./x86_64-native-bsdapp-gcc/app/testpmd --lcores='0@8,(4-5)@(8-11)' -n 4 -- -i --txfreet=32 --rxfreet=32 --txqflags=0xf01 --txrst=32
./x86_64-native-bsdapp-gcc/app/testpmd --lcores='1,2@(0-4,6),(3-4,6)@5,(7,8)' -n 4 -- -i --txfreet=32 --rxfreet=32 --txqflags=0xf01 --txrst=32
./x86_64-native-bsdapp-gcc/app/testpmd --lcores='(0,127)@(4,5)' -n 4 -- -i --txfreet=32 --rxfreet=32 --txqflags=0xf01 --txrst=32
./x86_64-native-bsdapp-gcc/app/testpmd --lcores='2-5,6,7-9' -n 4 -- -i --txfreet=32 --rxfreet=32 --txqflags=0xf01 --txrst=32
./x86_64-native-bsdapp-gcc/app/testpmd --lcores='2, (3-5)@ 3' -n 4 -- -i --txfreet=32 --rxfreet=32 --txqflags=0xf01 --txrst=32
./x86_64-native-bsdapp-gcc/app/testpmd --lcores='(0,64-66)@(4,5)' -n 4 -- -i --txfreet=32 --rxfreet=32 --txqflags=0xf01 --txrst=32
./x86_64-native-bsdapp-gcc/app/testpmd --lcores='(0,7-4)@(4,5)' -n 4 -- -i --txfreet=32 --rxfreet=32 --txqflags=0xf01 --txrst=32
./x86_64-native-bsdapp-gcc/app/testpmd --lcores='(0-,4-7)@(4,5)' -n 4 -- -i --txfreet=32 --rxfreet=32 --txqflags=0xf01 --txrst=32
./x86_64-native-bsdapp-gcc/app/testpmd --lcores='(-1,4-7)@(4,5)' -n 4 -- -i --txfreet=32 --rxfreet=32 --txqflags=0xf01 --txrst=32
./x86_64-native-bsdapp-gcc/app/testpmd --lcores='(0,4-7-9)@(4,5)' -n 4 -- -i --txfreet=32 --rxfreet=32 --txqflags=0xf01 --txrst=32
./x86_64-native-bsdapp-gcc/app/testpmd --lcores='(0,abcd)@(4,5)' -n 4 -- -i --txfreet=32 --rxfreet=32 --txqflags=0xf01 --txrst=32
./x86_64-native-bsdapp-gcc/app/testpmd --lcores='(0,4-7)@(1-,5)' -n 4 -- -i --txfreet=32 --rxfreet=32 --txqflags=0xf01 --txrst=32
./x86_64-native-bsdapp-gcc/app/testpmd --lcores='(0,4-7)@(-1,5)' -n 4 -- -i --txfreet=32 --rxfreet=32 --txqflags=0xf01 --txrst=32
./x86_64-native-bsdapp-gcc/app/testpmd --lcores='(0,4-7)@(4,5-8-9)' -n 4 -- -i --txfreet=32 --rxfreet=32 --txqflags=0xf01 --txrst=32
./x86_64-native-bsdapp-gcc/app/testpmd --lcores='(0,4-7)@(abc,5)' -n 4 -- -i --txfreet=32 --rxfreet=32 --txqflags=0xf01 --txrst=32
./x86_64-native-bsdapp-gcc/app/testpmd --lcores='(0,4-7)@(4,xyz)' -n 4 -- -i --txfreet=32 --rxfreet=32 --txqflags=0xf01 --txrst=32
./x86_64-native-bsdapp-gcc/app/testpmd --lcores='(0,4-7)=(8,9)' -n 4 -- -i --txfreet=32 --rxfreet=32 --txqflags=0xf01 --txrst=32
./x86_64-native-bsdapp-gcc/app/testpmd --lcores='2,3@4,(0-1,,4))' -n 4 -- -i --txfreet=32 --rxfreet=32 --txqflags=0xf01 --txrst=32
./x86_64-native-bsdapp-gcc/app/testpmd --lcores='[0-,4-7]@(4,5)' -n 4 -- -i --txfreet=32 --rxfreet=32 --txqflags=0xf01 --txrst=32
./x86_64-native-bsdapp-gcc/app/testpmd --lcores='(0-,4-7)@[4,5]' -n 4 -- -i --txfreet=32 --rxfreet=32 --txqflags=0xf01 --txrst=32
./x86_64-native-bsdapp-gcc/app/testpmd --lcores='3-4@3,2@5-6' -n 4 -- -i --txfreet=32 --rxfreet=32 --txqflags=0xf01 --txrst=32
./x86_64-native-bsdapp-gcc/app/testpmd --lcores='2,,3''2--3' -n 4 -- -i --txfreet=32 --rxfreet=32 --txqflags=0xf01 --txrst=32
./x86_64-native-bsdapp-gcc/app/testpmd --lcores='2,,,3''2--3' -n 4 -- -i --txfreet=32 --rxfreet=32 --txqflags=0xf01 --txrst=32
Best Regards,
Qun
Quoted 201 lines
-----Original Message-----
From: dev [mailto:[email protected]] On Behalf Of Cunming Liang
Sent: Sunday, February 15, 2015 11:15 AM
Subject: [dpdk-dev] [PATCH v7 00/19] support multi-pthread per core
v7 changes:
update EAL version map for new public EAL API
rollback to use
strnlen()passing EAL core optionv6 changes:
rename
RTE_RING_PAUSE_REP(_COUNT)and set default to 0rollback to use
RTE_MAX_LCOREwhen checking validlcore_idfor EAL threadv5 changes:
reorder some patch and split into addtional two patches
rte_thread_get_affinity()return type change to avoidadd
RTE_RING_PAUSE_REPinto config and by default turn offv4 changes:
new patch fixing
strnlen()invalid return in 32bit icc [03/17]update and add more comments on
sched_yield()[16/17]v3 changes:
new patch adding
sched_yield()inrte_ringto avoid long spin [16/17]v2 changes:
add '<number>-<number>' support for EAL option '--lcores' [02/17]
The patch series contain the enhancements of EAL and fixes for libraries to run
multi-pthreads(either EAL or non-EAL thread) per physical core.
Two major changes list as below:
- Extend the core affinity of each EAL thread to 1:n.
Each lcore stands for a EAL thread rather than a logical core.
The change adds new EAL option to allow static lcore to cpuset assginment.
Then a lcore(EAL thread) affinity to a cpuset, original 1:1 mapping is the special
case.
- Fix the libraries to allow running on any non-EAL thread.
It fix the gaps running libraries in non-EAL thread(dynamic created by user).
Each fix libraries take care the case of
rte_lcore_id()>=RTE_MAX_LCORE.Thanks a million for the comments from Konstantin, Bruce, Mirek and Stephen in
RFC review.
Cunming Liang (19):
eal: add cpuset into per EAL thread
lcore_configeal: fix
PAGE_SIZEredefine complaint on freebsdeal: new eal option '--lcores' for cpu assignment
eal: fix wrong
strnlen()return value in 32bit icceal: add support parsing
socket_idfrom cpuseteal: new TLS definition and API declaration
eal: add
eal_common_thread.cfor common thread APIeal: standardize init sequence between linux and bsd
eal: add
rte_gettid()to acquire unique system tideal: apply affinity of EAL thread by assigned cpuset
enic: fix re-define freebsd compile complain
malloc: fix the issue of
SOCKET_ID_ANYlog: fix the gap to support non-EAL thread
eal: set
_lcore_idand_socket_idto (-1) by defaulteal: fix recursive spinlock in non-EAL thraed
mempool: add support to non-EAL thread
ring: add support to non-EAL thread
ring: add
sched_yieldto avoid spin forevertimer: add support to non-EAL thread
config/common_bsdapp | 1 +config/common_linuxapp | 1 +lib/librte_eal/bsdapp/eal/Makefile | 1 +lib/librte_eal/bsdapp/eal/eal.c | 14 +-lib/librte_eal/bsdapp/eal/eal_lcore.c | 14 +lib/librte_eal/bsdapp/eal/eal_memory.c | 8 +-lib/librte_eal/bsdapp/eal/eal_thread.c | 77 ++---lib/librte_eal/bsdapp/eal/rte_eal_version.map | 2 +lib/librte_eal/common/eal_common_log.c | 17 +-lib/librte_eal/common/eal_common_options.c | 309++++++++++++++++++++-
lib/librte_eal/common/eal_common_thread.c | 150 ++++++++++lib/librte_eal/common/eal_options.h | 2 +lib/librte_eal/common/eal_thread.h | 47 ++++.../common/include/generic/rte_spinlock.h | 4 +-lib/librte_eal/common/include/rte_eal.h | 27 ++lib/librte_eal/common/include/rte_lcore.h | 40 ++-lib/librte_eal/common/include/rte_log.h | 5 +lib/librte_eal/linuxapp/eal/Makefile | 4 +lib/librte_eal/linuxapp/eal/eal.c | 8 +-lib/librte_eal/linuxapp/eal/eal_lcore.c | 15 +-lib/librte_eal/linuxapp/eal/eal_thread.c | 77 ++---lib/librte_eal/linuxapp/eal/rte_eal_version.map | 2 +lib/librte_malloc/malloc_heap.h | 7 +-lib/librte_mempool/rte_mempool.h | 18 +-lib/librte_pmd_enic/enic.h | 4 +-lib/librte_pmd_enic/enic_compat.h | 2 +-lib/librte_pmd_enic/vnic/vnic_dev.c | 6 +-lib/librte_ring/rte_ring.h | 41 ++-lib/librte_timer/rte_timer.c | 32 ++-lib/librte_timer/rte_timer.h | 4 +-30 files changed, 770 insertions(+), 169 deletions(-) create mode 100644
lib/librte_eal/common/eal_common_thread.c--
1.8.1.4