From: "Liu, Chuansheng" <chuansheng.liu@intel.com>
To: Thomas Gleixner <tglx@linutronix.de>
Cc: Oliver Neukum <oneukum@suse.de>,
"john.stultz@linaro.org" <john.stultz@linaro.org>,
"gregkh@linuxfoundation.org" <gregkh@linuxfoundation.org>,
"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
"Liu, Chuansheng" <chuansheng.liu@intel.com>
Subject: RE: [PATCH 1/3] alarmtimer: Replace the spinlock rtcdev_lock with mutex
Date: Fri, 2 Nov 2012 03:32:26 +0000 [thread overview]
Message-ID: <27240C0AC20F114CBF8149A2696CBE4A1BAAC8@SHSMSX101.ccr.corp.intel.com> (raw)
In-Reply-To: <alpine.LFD.2.02.1211012306240.2756@ionos>
> It's safe to do in any code path which wants to use rtcdev:
>
> if (!rtcdev)
> return -ENODEV:
> do_something(rtcdev);
>
Really thanks your analysis and sharing, learn something.
And preparing a new patch with your comments for this point.
Subject: [PATCH] alarmtimer: Removing lock at alarmtimer_get_rtcdev()
[From Thomas comments]
"Protecting" the dereferencing of rtcdev with any kind of lock does
not provide any useful protection at all.
Moreover, alarmtimer_rtc_add_device just set the rtc device ONCE,
and the device will never go away and is never going to change, it's
completely pointless to have a lock in alarmtimer_get_rtcdev() at all.
So this patch remove the lock/unlock actions in alarmtimer_get_rtcdev().
Signed-off-by: liu chuansheng <chuansheng.liu@intel.com>
---
kernel/time/alarmtimer.c | 21 +++++++--------------
1 files changed, 7 insertions(+), 14 deletions(-)
diff --git a/kernel/time/alarmtimer.c b/kernel/time/alarmtimer.c
index f11d83b..eed3b26 100644
--- a/kernel/time/alarmtimer.c
+++ b/kernel/time/alarmtimer.c
@@ -62,14 +62,7 @@ static DEFINE_SPINLOCK(rtcdev_lock);
*/
struct rtc_device *alarmtimer_get_rtcdev(void)
{
- unsigned long flags;
- struct rtc_device *ret;
-
- spin_lock_irqsave(&rtcdev_lock, flags);
- ret = rtcdev;
- spin_unlock_irqrestore(&rtcdev_lock, flags);
-
- return ret;
+ return rtcdev;
}
@@ -224,10 +217,10 @@ static int alarmtimer_suspend(struct device *dev)
freezer_delta = ktime_set(0, 0);
spin_unlock_irqrestore(&freezer_delta_lock, flags);
- rtc = alarmtimer_get_rtcdev();
/* If we have no rtcdev, just return */
- if (!rtc)
+ if (!rtcdev)
return 0;
+ rtc = rtcdev;
/* Find the soonest timer to expire*/
for (i = 0; i < ALARM_NUMTYPE; i++) {
@@ -444,7 +437,7 @@ static int alarm_clock_getres(const clockid_t which_clock, struct timespec *tp)
{
clockid_t baseid = alarm_bases[clock2alarm(which_clock)].base_clockid;
- if (!alarmtimer_get_rtcdev())
+ if (!rtcdev)
return -ENOTSUPP;
return hrtimer_get_res(baseid, tp);
@@ -461,7 +454,7 @@ static int alarm_clock_get(clockid_t which_clock, struct timespec *tp)
{
struct alarm_base *base = &alarm_bases[clock2alarm(which_clock)];
- if (!alarmtimer_get_rtcdev())
+ if (!rtcdev)
return -ENOTSUPP;
*tp = ktime_to_timespec(base->gettime());
@@ -479,7 +472,7 @@ static int alarm_timer_create(struct k_itimer *new_timer)
enum alarmtimer_type type;
struct alarm_base *base;
- if (!alarmtimer_get_rtcdev())
+ if (!rtcdev)
return -ENOTSUPP;
if (!capable(CAP_WAKE_ALARM))
@@ -682,7 +675,7 @@ static int alarm_timer_nsleep(const clockid_t which_clock, int flags,
int ret = 0;
struct restart_block *restart;
- if (!alarmtimer_get_rtcdev())
+ if (!rtcdev)
return -ENOTSUPP;
if (!capable(CAP_WAKE_ALARM))
--
1.7.0.4
next prev parent reply other threads:[~2012-11-02 3:32 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-10-31 16:20 Chuansheng Liu
2012-10-31 9:03 ` Oliver Neukum
2012-11-01 0:02 ` Liu, Chuansheng
2012-11-01 22:43 ` Thomas Gleixner
2012-11-02 3:32 ` Liu, Chuansheng [this message]
2012-10-31 16:23 ` [PATCH 2/3] alarmtimer: Using the alarmtimer_get_rtcdev for all posix clock interface Chuansheng Liu
2012-11-01 22:55 ` Thomas Gleixner
2012-11-02 3:41 ` Liu, Chuansheng
2012-11-02 6:10 ` Liu, Chuansheng
2012-10-31 16:25 ` [PATCH 3/3] alarmtimer: cleanup the POSIX clock interface without CONFIG_RTC_CLASS Chuansheng Liu
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=27240C0AC20F114CBF8149A2696CBE4A1BAAC8@SHSMSX101.ccr.corp.intel.com \
--to=chuansheng.liu@intel.com \
--cc=gregkh@linuxfoundation.org \
--cc=john.stultz@linaro.org \
--cc=linux-kernel@vger.kernel.org \
--cc=oneukum@suse.de \
--cc=tglx@linutronix.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®