About the memory ordering and function call
Hi,
Notsure it's suitable to ask here,but a strange memory order related problem happens.
Related codes are like below (somewhat simplified)
------
struct my_work {
/* someunrelated variants */
struct SOME_OTHER_STRUCT *my_pointer; <<< Attention here struct work_struct normal_work;
};
void my_queue_work(struct workqueue_struct *wq, <<< wq is WQ_UNBOUND workqueue
struct my_work *work)
{
/*
* the work->normal_work is initialized somewhere else,
* and the work job will use the work->my_pointer.
*/
work->my_pointer = something; <<< The problem
/* Do something else */queue_work(wq, work->normal_work);
}
------
The codes runs fine on all my *INTEL* boxes but kernel panic on *AMD* boxes(othertesters', so I can't reproduce it),
when the work is executed, a NULL pointer exception will happen. After tracing the backtrace,it happens that the work->my_pointer is not set to proper address and isstill NULL.
So I have some questionsabout the problem.
1) Should I add an smp_mb() behind "work->my_pointer = something"?
2) Why the smp_mb() in queue_work() function can't ensure "work->my_pointer" is set?
More accuratly, will smp_mb() affect outside of a function call? Forreference, the smp_mb() lies like below:queue_work()queue_work_on()__queue_work()insert_work()smp_mb()
3) Why INTEL CPUs can't trigger the problem?
Wikipedia says that AMD CPUs has somewhat weak memory ordering than Intel, may it be the problem?
Thanks,
Qu
Hi Qu,
Don't have the answer, but perhaps try different compilers, different
optimization options? Once you've found a combination, then take the compiled instructions, and I believe the compiler guys might be better help then in understanding/fixing the instruction ordering/etc..
Hendrik
Quoted 57 lines · Qu Wenruo
Hi,
Notsure it's suitable to ask here,but a strange memory order related problem happens.
Related codes are like below (somewhat simplified)------
structmy_work{
/* someunrelated variants */
structSOME_OTHER_STRUCT*my_pointer; <<< Attention here structwork_structnormal_work;
};void my_queue_work(struct
workqueue_struct*wq, <<< wq isWQ_UNBOUNDworkqueue
structmy_work*work)
{
/*
* thework->normal_workis initialized somewhere else,
* and the work job will use thework->my_pointer.
*/
work->my_pointer= something; <<< The problem
/* Do something else */queue_work(wq, work->normal_work);
}
------The codes runs fine on all my *INTEL* boxes but kernel panic on *AMD*
boxes(othertesters', so I can't reproduce it),
when the work is executed, a NULL pointer exception will happen. After tracing the backtrace,it happens that thework->my_pointeris not set to proper address and isstill NULL.So I have some questionsabout the problem.
1) Should I add ansmp_mb()behind "work->my_pointer= something"?2) Why the
smp_mb()inqueue_work()function can't ensure "work->my_pointer" is set?
More accuratly, willsmp_mb()affect outside of a function call? Forreference, thesmp_mb()lies like below:queue_work()queue_work_on()__queue_work()insert_work()smp_mb()3) Why INTEL CPUs can't trigger the problem?
Wikipedia says that AMD CPUs has somewhat weak memory ordering than Intel, may it be the problem?Thanks,
Qu
--
To unsubscribe from this list: send the line "unsubscribe linux-c-programming" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html