* to schedule() or not to schedule() ?
@ 2008-08-03 18:33 Kevin Diggs
2008-08-05 18:37 ` Chris Friesen
0 siblings, 1 reply; 6+ messages in thread
From: Kevin Diggs @ 2008-08-03 18:33 UTC (permalink / raw)
To: linuxppc-dev
Hi,
I have the following near the top of my cpufreq driver target routine:
while(test_and_set_bit(cf750gxmCfgChangeBit,&cf750gxvStateBits)) {
/*
* Someone mucking with our cfg? (I hope it is ok to call
* schedule() here! - truth is I have no idea what I am doing
* ... my reasoning is I want to yeild the cpu so whoever is
* mucking around can finish)
*/
schedule();
}
This is to prevent bad things from happening if someone is trying to
change a parameter for the driver via sysfs while the target routine is
running. Fortunately, because I had a bug where this bit was not getting
cleared on one of the paths through the target routine ... I now know it
is not safe to call schedule (it got stuck in there - knocked out my adb
keyboard! - (I think target is called from a timer that the governor
sets up ... interrupt context?)).
How does one very briefly yield the cpu in this context?
kevin
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: to schedule() or not to schedule() ?
2008-08-03 18:33 to schedule() or not to schedule() ? Kevin Diggs
@ 2008-08-05 18:37 ` Chris Friesen
2008-08-05 19:26 ` Kevin Diggs
0 siblings, 1 reply; 6+ messages in thread
From: Chris Friesen @ 2008-08-05 18:37 UTC (permalink / raw)
To: Kevin Diggs; +Cc: linuxppc-dev
Kevin Diggs wrote:
> Hi,
>
>
> I have the following near the top of my cpufreq driver target routine:
>
> while(test_and_set_bit(cf750gxmCfgChangeBit,&cf750gxvStateBits)) {
> /*
> * Someone mucking with our cfg? (I hope it is ok to call
> * schedule() here! - truth is I have no idea what I am doing
> * ... my reasoning is I want to yeild the cpu so whoever is
> * mucking around can finish)
> */
> schedule();
> }
>
> This is to prevent bad things from happening if someone is trying to
> change a parameter for the driver via sysfs while the target routine is
> running. Fortunately, because I had a bug where this bit was not getting
> cleared on one of the paths through the target routine ... I now know it
> is not safe to call schedule (it got stuck in there - knocked out my adb
> keyboard! - (I think target is called from a timer that the governor
> sets up ... interrupt context?)).
Is the issue that someone may be in the middle of a multi-stage
procedure, and you've woken up partway through?
If so, what about simply rescheduling the timer for some short time in
the future and aborting the current call?
Chris
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: to schedule() or not to schedule() ?
2008-08-05 18:37 ` Chris Friesen
@ 2008-08-05 19:26 ` Kevin Diggs
2008-08-05 23:00 ` Michael Ellerman
0 siblings, 1 reply; 6+ messages in thread
From: Kevin Diggs @ 2008-08-05 19:26 UTC (permalink / raw)
To: Chris Friesen; +Cc: linuxppc-dev
Chris Friesen wrote:
> Kevin Diggs wrote:
>
>> Hi,
>>
>>
>> I have the following near the top of my cpufreq driver target
>> routine:
>>
>> while(test_and_set_bit(cf750gxmCfgChangeBit,&cf750gxvStateBits)) {
>> /*
>> * Someone mucking with our cfg? (I hope it is ok to call
>> * schedule() here! - truth is I have no idea what I am doing
>> * ... my reasoning is I want to yeild the cpu so whoever is
>> * mucking around can finish)
>> */
>> schedule();
>> }
>>
>> This is to prevent bad things from happening if someone is trying to
>> change a parameter for the driver via sysfs while the target routine
>> is running. Fortunately, because I had a bug where this bit was not
>> getting cleared on one of the paths through the target routine ... I
>> now know it is not safe to call schedule (it got stuck in there -
>> knocked out my adb keyboard! - (I think target is called from a timer
>> that the governor sets up ... interrupt context?)).
>
>
> Is the issue that someone may be in the middle of a multi-stage
> procedure, and you've woken up partway through?
>
> If so, what about simply rescheduling the timer for some short time in
> the future and aborting the current call?
>
> Chris
>
Chris,
Thanks for taking the time to reply. The parameter in question modifies
the frequency table. It is used several times in the target routine.
I've addressed the issue by making a local copy of the frequency table
upon entry to the target routine and use that while there. I don't care
who wins the race.
kevin
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: to schedule() or not to schedule() ?
2008-08-05 19:26 ` Kevin Diggs
@ 2008-08-05 23:00 ` Michael Ellerman
2008-08-06 1:59 ` Kevin Diggs
0 siblings, 1 reply; 6+ messages in thread
From: Michael Ellerman @ 2008-08-05 23:00 UTC (permalink / raw)
To: Kevin Diggs; +Cc: linuxppc-dev
[-- Attachment #1: Type: text/plain, Size: 2210 bytes --]
On Tue, 2008-08-05 at 12:26 -0700, Kevin Diggs wrote:
> Chris Friesen wrote:
> > Kevin Diggs wrote:
> >> I have the following near the top of my cpufreq driver target
> >> routine:
> >>
> >> while(test_and_set_bit(cf750gxmCfgChangeBit,&cf750gxvStateBits)) {
> >> /*
> >> * Someone mucking with our cfg? (I hope it is ok to call
> >> * schedule() here! - truth is I have no idea what I am doing
> >> * ... my reasoning is I want to yeild the cpu so whoever is
> >> * mucking around can finish)
> >> */
> >> schedule();
> >> }
> >>
> >> This is to prevent bad things from happening if someone is trying to
> >> change a parameter for the driver via sysfs while the target routine
> >> is running. Fortunately, because I had a bug where this bit was not
> >> getting cleared on one of the paths through the target routine ... I
> >> now know it is not safe to call schedule (it got stuck in there -
> >> knocked out my adb keyboard! - (I think target is called from a timer
> >> that the governor sets up ... interrupt context?)).
> >
> >
> > Is the issue that someone may be in the middle of a multi-stage
> > procedure, and you've woken up partway through?
> >
> > If so, what about simply rescheduling the timer for some short time in
> > the future and aborting the current call?
> Chris,
>
> Thanks for taking the time to reply. The parameter in question modifies
> the frequency table. It is used several times in the target routine.
> I've addressed the issue by making a local copy of the frequency table
> upon entry to the target routine and use that while there. I don't care
> who wins the race.
How are you copying the table? Is it an atomic copy? Otherwise you could
just end up copying the table while it's being updated, and you get a
copy of the partially updated table.
Don't you just need a spinlock?
cheers
--
Michael Ellerman
OzLabs, IBM Australia Development Lab
wwweb: http://michael.ellerman.id.au
phone: +61 2 6212 1183 (tie line 70 21183)
We do not inherit the earth from our ancestors,
we borrow it from our children. - S.M.A.R.T Person
[-- Attachment #2: This is a digitally signed message part --]
[-- Type: application/pgp-signature, Size: 189 bytes --]
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: to schedule() or not to schedule() ?
2008-08-05 23:00 ` Michael Ellerman
@ 2008-08-06 1:59 ` Kevin Diggs
2008-08-06 21:12 ` Arnd Bergmann
0 siblings, 1 reply; 6+ messages in thread
From: Kevin Diggs @ 2008-08-06 1:59 UTC (permalink / raw)
To: linuxppc-dev
Michael Ellerman wrote:
> On Tue, 2008-08-05 at 12:26 -0700, Kevin Diggs wrote:
>
>>Chris Friesen wrote:
>>
>>>Kevin Diggs wrote:
>
>
>>>> I have the following near the top of my cpufreq driver target
>>>>routine:
>>>>
>>>>while(test_and_set_bit(cf750gxmCfgChangeBit,&cf750gxvStateBits)) {
>>>> /*
>>>> * Someone mucking with our cfg? (I hope it is ok to call
>>>> * schedule() here! - truth is I have no idea what I am doing
>>>> * ... my reasoning is I want to yeild the cpu so whoever is
>>>> * mucking around can finish)
>>>> */
>>>> schedule();
>>>>}
>>>>
>>>>This is to prevent bad things from happening if someone is trying to
>>>>change a parameter for the driver via sysfs while the target routine
>>>>is running. Fortunately, because I had a bug where this bit was not
>>>>getting cleared on one of the paths through the target routine ... I
>>>>now know it is not safe to call schedule (it got stuck in there -
>>>>knocked out my adb keyboard! - (I think target is called from a timer
>>>>that the governor sets up ... interrupt context?)).
>>>
>>>
>>>Is the issue that someone may be in the middle of a multi-stage
>>>procedure, and you've woken up partway through?
>>>
>>>If so, what about simply rescheduling the timer for some short time in
>>>the future and aborting the current call?
>
>
>>Chris,
>>
>> Thanks for taking the time to reply. The parameter in question modifies
>>the frequency table. It is used several times in the target routine.
>>I've addressed the issue by making a local copy of the frequency table
>>upon entry to the target routine and use that while there. I don't care
>>who wins the race.
>
>
> How are you copying the table? Is it an atomic copy? Otherwise you could
> just end up copying the table while it's being updated, and you get a
> copy of the partially updated table.
>
> Don't you just need a spinlock?
>
> cheers
>
In the initialization routine I create 2 tables. One is a table with all
the frequencies. The other has just the min and max. The parameter just
changes a pointer to point to one table or the other. The above
addressing of the issue should really say "a local copy of the pointer
to the frequency table".
Thanks for the reply!
For the purpose of learning, there is no direct, correct way to yield
the cpu when in a timer fired routine, right?
kevin
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: to schedule() or not to schedule() ?
2008-08-06 1:59 ` Kevin Diggs
@ 2008-08-06 21:12 ` Arnd Bergmann
0 siblings, 0 replies; 6+ messages in thread
From: Arnd Bergmann @ 2008-08-06 21:12 UTC (permalink / raw)
To: linuxppc-dev; +Cc: Kevin Diggs
On Wednesday 06 August 2008, Kevin Diggs wrote:
> For the purpose of learning, there is no direct, correct way to yield
> the cpu when in a timer fired routine, right?
>
No, in a timer, you interrupt a totally unrelated thread, so sleeping
would prevent that from running on, as well as preventing other timers
from being run, so it's not an option.
One thing that might work for you would be to re-arm the existing
timer and return from your function, so you get back to it after
a short while.
Arnd <><
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2008-08-06 21:12 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-08-03 18:33 to schedule() or not to schedule() ? Kevin Diggs
2008-08-05 18:37 ` Chris Friesen
2008-08-05 19:26 ` Kevin Diggs
2008-08-05 23:00 ` Michael Ellerman
2008-08-06 1:59 ` Kevin Diggs
2008-08-06 21:12 ` Arnd Bergmann
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).