* About the memory ordering and function call
@ 2014-02-05 1:23 Qu Wenruo
2014-02-05 5:14 ` Hendrik Visage
0 siblings, 1 reply; 2+ messages in thread
From: Qu Wenruo @ 2014-02-05 1:23 UTC (permalink / raw)
To: linux-c-programming
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
^ permalink raw reply [flat|nested] 2+ messages in thread* Re: About the memory ordering and function call
2014-02-05 1:23 About the memory ordering and function call Qu Wenruo
@ 2014-02-05 5:14 ` Hendrik Visage
0 siblings, 0 replies; 2+ messages in thread
From: Hendrik Visage @ 2014-02-05 5:14 UTC (permalink / raw)
To: Qu Wenruo; +Cc: Linux C Programming List
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
On Wed, Feb 5, 2014 at 3:23 AM, Qu Wenruo <quwenruo@cn.fujitsu.com> wrote:
> 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
> --
> To unsubscribe from this list: send the line "unsubscribe linux-c-programming" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at http://vger.kernel.org/majordomo-info.html
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2014-02-05 5:14 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-02-05 1:23 About the memory ordering and function call Qu Wenruo
2014-02-05 5:14 ` Hendrik Visage
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).