Skip to contentSkip to conversation

use time_is_xxx() instead of jiffies judgment

PATCH In review Qing Wang 3 participants 17 messages Feb 11, 2022 – Feb 14, 2022 1 message not in the archive

Subsystems (13)
lore
Share & tools
lore

Qing Wang

author
#0 lore raw

v2 cover use time_is_xxx() instead of jiffies judgment

From: Wang Qing <[email protected]>

It is better to use time_is_xxx() directly instead of jiffies judgment for understanding.

Batch them in a series suggested by Joe.

Wang Qing (14):
block: xen: use time_is_before_eq_jiffies() instead of jiffies judgment
clk: mvebu: use time_is_before_eq_jiffies() instead of jiffies judgment
gpu: drm: i915: use time_is_after_jiffies() instead of jiffies judgment
gpu: drm: radeon: use time_is_before_jiffies() instead of jiffies judgment
hid: use time_is_after_jiffies() instead of jiffies judgment
input: serio: use time_is_before_jiffies() instead of jiffies judgment
md: use time_is_before_jiffies(() instead of jiffies judgment
md: use time_is_before_eq_jiffies() instead of jiffies judgment
media: si21xx: use time_is_before_jiffies() instead of jiffies judgment
media: stv0299: use time_is_before_jiffies() instead of jiffies judgment
media: tda8083: use time_is_after_jiffies() instead of jiffies judgment
media: wl128x: use time_is_before_jiffies() instead of jiffies judgment
media: vivid: use time_is_after_jiffies() instead of jiffies judgment

 drivers/block/xen-blkback/blkback.c                    | 5 +++--
 drivers/clk/mvebu/armada-37xx-periph.c                 | 3 ++-
 drivers/gpu/drm/i915/gt/intel_gt_buffer_pool.c         | 2 +-
 drivers/gpu/drm/radeon/radeon_pm.c                     | 3 ++-
 drivers/hid/intel-ish-hid/ipc/ipc.c                    | 2 +-
 drivers/input/serio/ps2-gpio.c                         | 4 ++--
 drivers/md/dm-thin.c                                   | 2 +-
 drivers/md/dm-writecache.c                             | 5 +++--
 drivers/media/dvb-frontends/si21xx.c                   | 2 +-
 drivers/media/dvb-frontends/stv0299.c                  | 4 ++--
 drivers/media/dvb-frontends/tda8083.c                  | 2 +-
 drivers/media/radio/wl128x/fmdrv_common.c              | 3 ++-
 drivers/media/test-drivers/vivid/vivid-kthread-cap.c   | 3 ++-
 drivers/media/test-drivers/vivid/vivid-kthread-out.c   | 3 ++-
 drivers/media/test-drivers/vivid/vivid-kthread-touch.c | 3 ++-
 drivers/media/test-drivers/vivid/vivid-sdr-cap.c       | 3 ++-
 17 files changed, 31 insertions(+), 22 deletions(-)
Signature · 1 line
2.7.4
author
#1 lore raw

PATCH v2 1/13 block: xen: use time_is_before_eq_jiffies() instead of jiffies judgment

From: Wang Qing <[email protected]>

It is better to use time_xxx() directly instead of jiffies judgment for understanding.

---
 drivers/block/xen-blkback/blkback.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
drivers/block/xen-blkback/blkback.c +3 -2
index d1e2646..aecc1f4
@@ -42,6 +42,7 @@
 #include <linux/delay.h>
 #include <linux/freezer.h>
 #include <linux/bitmap.h>
+#include <linux/jiffies.h>
 
 #include <xen/events.h>
 #include <xen/page.h>
@@ -134,8 +135,8 @@ module_param(log_stats, int, 0644);
 
 static inline bool persistent_gnt_timeout(struct persistent_gnt *persistent_gnt)
 {
-	return pgrant_timeout && (jiffies - persistent_gnt->last_used >=
-			HZ * pgrant_timeout);
+	return pgrant_timeout && time_is_before_eq_jiffies(
+			persistent_gnt->last_used + HZ * pgrant_timeout);
 }
 
 #define vaddr(page) ((unsigned long)pfn_to_kaddr(page_to_pfn(page)))
Signature · 1 line
2.7.4
author
#2 lore raw

PATCH v2 2/13 clk: mvebu: use time_is_before_eq_jiffies() instead of jiffies judgment

In reply to Qing Wang

From: Wang Qing <[email protected]>

It is better use time_xxx() directly instead of jiffies judgment for understanding.

---
 drivers/clk/mvebu/armada-37xx-periph.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/clk/mvebu/armada-37xx-periph.c +2 -1
index 32ac6b6..14d73f8
@@ -25,6 +25,7 @@
 #include <linux/platform_device.h>
 #include <linux/regmap.h>
 #include <linux/slab.h>
+#include <linux/jiffies.h>
 
 #define TBG_SEL		0x0
 #define DIV_SEL0	0x4
@@ -541,7 +542,7 @@ static void clk_pm_cpu_set_rate_wa(struct clk_pm_cpu *pm_cpu,
 	 * We are going to L0 with rate >= 1GHz. Check whether we have been at
 	 * L1 for long enough time. If not, go to L1 for 20ms.
 	 */
-	if (pm_cpu->l1_expiration && jiffies >= pm_cpu->l1_expiration)
+	if (pm_cpu->l1_expiration && time_is_before_eq_jiffies(pm_cpu->l1_expiration))
 		goto invalidate_l1_exp;
 
 	regmap_update_bits(base, ARMADA_37XX_NB_CPU_LOAD,
Signature · 1 line
2.7.4
author
#3 lore raw

PATCH v2 3/13 gpu: drm: i915: use time_is_after_jiffies() instead of jiffies judgment

In reply to Qing Wang

From: Wang Qing <[email protected]>

It is better use time_xxx() directly instead of jiffies judgment for understanding.

---
 drivers/gpu/drm/i915/gt/intel_gt_buffer_pool.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/i915/gt/intel_gt_buffer_pool.c +1 -1
index 9db3dcb..b289abb
@@ -56,7 +56,7 @@ static bool pool_free_older_than(struct intel_gt_buffer_pool *pool, long keep)
 				node = list_entry(pos, typeof(*node), link);
 
 				age = READ_ONCE(node->age);
-				if (!age || jiffies - age < keep)
+				if (!age || time_is_after_jiffies(age + keep))
 					break;
 
 				/* Check we are the first to claim this node */
Signature · 1 line
2.7.4
author
#4 lore raw

PATCH v2 4/13 gpu: drm: radeon: use time_is_before_jiffies() instead of jiffies judgment

In reply to Qing Wang

From: Wang Qing <[email protected]>

It is better to use time_xxx() directly instead of jiffies judgment for understanding.

---
 drivers/gpu/drm/radeon/radeon_pm.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/gpu/drm/radeon/radeon_pm.c +2 -1
index c67b6dd..53d536a
@@ -25,6 +25,7 @@
 #include <linux/hwmon.h>
 #include <linux/pci.h>
 #include <linux/power_supply.h>
+#include <linux/jiffies.h>
 
 #include <drm/drm_vblank.h>
 
@@ -1899,7 +1900,7 @@ static void radeon_dynpm_idle_work_handler(struct work_struct *work)
 		 * to false since we want to wait for vbl to avoid flicker.
 		 */
 		if (rdev->pm.dynpm_planned_action != DYNPM_ACTION_NONE &&
-		    jiffies > rdev->pm.dynpm_action_timeout) {
+		    time_is_before_jiffies(rdev->pm.dynpm_action_timeout)) {
 			radeon_pm_get_dynpm_state(rdev);
 			radeon_pm_set_clocks(rdev);
 		}
Signature · 1 line
2.7.4
author
#5 lore raw

PATCH v2 5/13 hid: use time_is_after_jiffies() instead of jiffies judgment

In reply to Qing Wang

From: Wang Qing <[email protected]>

It is better to use time_xxx() directly instead of jiffies judgment for understanding.

---
 drivers/hid/intel-ish-hid/ipc/ipc.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/hid/intel-ish-hid/ipc/ipc.c +1 -1
index 8ccb246..15e1423
@@ -578,7 +578,7 @@ static void _ish_sync_fw_clock(struct ishtp_device *dev)
 	static unsigned long	prev_sync;
 	uint64_t	usec;
 
-	if (prev_sync && jiffies - prev_sync < 20 * HZ)
+	if (prev_sync && time_is_after_jiffies(prev_sync + 20 * HZ))
 		return;
 
 	prev_sync = jiffies;
Signature · 1 line
2.7.4
maintainer Acked-by on v2 5/13
#6 lore raw

Re: [PATCH V2 5/13] hid: use time_is_after_jiffies() instead of jiffies judgment

Quoted 6 lines · Qing Wang

From: Wang Qing <[email protected]>

It is better to use time_xxx() directly instead of jiffies judgment for understanding.

Quoted 19 lines

---
 drivers/hid/intel-ish-hid/ipc/ipc.c | 2 +-

 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/hid/intel- renamed from drivers/hid/intel-ish-hid/ipc/ipc.c +0 -0

ish-hid/ipc/ipc.c
index 8ccb246..15e1423

drivers/hid/intel-ish-hid/ipc/ipc.c +0 -0
@@ -578,7 +578,7 @@ static void _ish_sync_fw_clock(struct
 ishtp_device *dev)
         static unsigned long    prev_sync;
         uint64_t        usec;


-       if (prev_sync && jiffies - prev_sync < 20 * HZ)
+       if (prev_sync && time_is_after_jiffies(prev_sync + 20 * HZ)) return;

        prev_sync = jiffies;

author
#7 lore raw

PATCH v2 6/13 input: serio: use time_is_before_jiffies() instead of jiffies judgment

In reply to Qing Wang

From: Wang Qing <[email protected]>

It is better to use time_xxx() directly instead of jiffies judgment for understanding.

---
 drivers/input/serio/ps2-gpio.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/input/serio/ps2-gpio.c +2 -2
index 8970b49..7834296
@@ -136,7 +136,7 @@ static irqreturn_t ps2_gpio_irq_rx(struct ps2_gpio_data *drvdata)
 	if (old_jiffies == 0)
 		old_jiffies = jiffies;
 
-	if ((jiffies - old_jiffies) > usecs_to_jiffies(100)) {
+	if (time_is_before_jiffies(old_jiffies + usecs_to_jiffies(100))) {
 		dev_err(drvdata->dev,
 			"RX: timeout, probably we missed an interrupt\n");
 		goto err;
@@ -237,7 +237,7 @@ static irqreturn_t ps2_gpio_irq_tx(struct ps2_gpio_data *drvdata)
 	if (old_jiffies == 0)
 		old_jiffies = jiffies;
 
-	if ((jiffies - old_jiffies) > usecs_to_jiffies(100)) {
+	if (time_is_before_jiffies(old_jiffies + usecs_to_jiffies(100))) {
 		dev_err(drvdata->dev,
 			"TX: timeout, probably we missed an interrupt\n");
 		goto err;
Signature · 1 line
2.7.4
author
#8 lore raw

PATCH v2 7/13 md: use time_is_before_jiffies(() instead of jiffies judgment

In reply to Qing Wang

From: Wang Qing <[email protected]>

It is better to use time_xxx() directly instead of jiffies judgment for understanding.

---
 drivers/md/dm-thin.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/md/dm-thin.c +1 -1
index f4234d6..dced764
@@ -161,7 +161,7 @@ static void throttle_work_start(struct throttle *t)
 
 static void throttle_work_update(struct throttle *t)
 {
-	if (!t->throttle_applied && jiffies > t->threshold) {
+	if (!t->throttle_applied && time_is_before_jiffies(t->threshold)) {
 		down_write(&t->lock);
 		t->throttle_applied = true;
 	}
Signature · 1 line
2.7.4
author
#9 lore raw

PATCH v2 9/13 media: si21xx: use time_is_before_jiffies() instead of jiffies judgment

In reply to Qing Wang

From: Wang Qing <[email protected]>

It is better to use time_xxx() directly instead of jiffies judgment for understanding.

---
 drivers/media/dvb-frontends/si21xx.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/media/dvb-frontends/si21xx.c +1 -1
index 001b235..1c6cf76
@@ -336,7 +336,7 @@ static int si21xx_wait_diseqc_idle(struct si21xx_state *state, int timeout)
 	dprintk("%s\n", __func__);
 
 	while ((si21_readreg(state, LNB_CTRL_REG_1) & 0x8) == 8) {
-		if (jiffies - start > timeout) {
+		if (time_is_before_jiffies(start + timeout)) {
 			dprintk("%s: timeout!!\n", __func__);
 			return -ETIMEDOUT;
 		}
Signature · 1 line
2.7.4
author
#10 lore raw

PATCH v2 10/13 md: use time_is_before_eq_jiffies() instead of jiffies judgment

In reply to Qing Wang

From: Wang Qing <[email protected]>

It is better to use time_xxx() directly instead of jiffies judgment for understanding.

---
 drivers/md/dm-writecache.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
drivers/md/dm-writecache.c +3 -2
index 5630b47..125bb5d
@@ -16,6 +16,7 @@
 #include <linux/pfn_t.h>
 #include <linux/libnvdimm.h>
 #include <linux/delay.h>
+#include <linux/jiffies.h>
 #include "dm-io-tracker.h"
 
 #define DM_MSG_PREFIX "writecache"
@@ -1971,8 +1972,8 @@ static void writecache_writeback(struct work_struct *work)
 	while (!list_empty(&wc->lru) &&
 	       (wc->writeback_all ||
 		wc->freelist_size + wc->writeback_size <= wc->freelist_low_watermark ||
-		(jiffies - container_of(wc->lru.prev, struct wc_entry, lru)->age >=
-		 wc->max_age - wc->max_age / MAX_AGE_DIV))) {
+		time_is_before_eq_jiffies(container_of(wc->lru.prev, struct wc_entry, lru)->age
+		  + wc->max_age - wc->max_age / MAX_AGE_DIV)) {
 
 		n_walked++;
 		if (unlikely(n_walked > WRITEBACK_LATENCY) &&
Signature · 1 line
2.7.4
author
#11 lore raw

PATCH v2 10/13 media: stv0299: use time_is_before_jiffies() instead of jiffies judgment

In reply to Qing Wang

From: Wang Qing <[email protected]>

It is better to use time_xxx() directly instead of jiffies judgment for understanding.

---
 drivers/media/dvb-frontends/stv0299.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/media/dvb-frontends/stv0299.c +2 -2
index 421395e..867ae04
@@ -183,7 +183,7 @@ static int stv0299_wait_diseqc_fifo (struct stv0299_state* state, int timeout)
 	dprintk ("%s\n", __func__);
 
 	while (stv0299_readreg(state, 0x0a) & 1) {
-		if (jiffies - start > timeout) {
+		if (time_is_before_jiffies(start + timeout)) {
 			dprintk ("%s: timeout!!\n", __func__);
 			return -ETIMEDOUT;
 		}
@@ -200,7 +200,7 @@ static int stv0299_wait_diseqc_idle (struct stv0299_state* state, int timeout)
 	dprintk ("%s\n", __func__);
 
 	while ((stv0299_readreg(state, 0x0a) & 3) != 2 ) {
-		if (jiffies - start > timeout) {
+		if (time_is_before_jiffies(start + timeout)) {
 			dprintk ("%s: timeout!!\n", __func__);
 			return -ETIMEDOUT;
 		}
Signature · 1 line
2.7.4
author
#12 lore raw

PATCH v2 11/13 media: tda8083: use time_is_after_jiffies() instead of jiffies judgment

In reply to Qing Wang

From: Wang Qing <[email protected]>

It is better to use time_xxx() directly instead of jiffies judgment for understanding.

---
 drivers/media/dvb-frontends/tda8083.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/media/dvb-frontends/tda8083.c +1 -1
index 5be11fd..49c4fe1
@@ -162,7 +162,7 @@ static void tda8083_wait_diseqc_fifo (struct tda8083_state* state, int timeout)
 {
 	unsigned long start = jiffies;
 
-	while (jiffies - start < timeout &&
+	while (time_is_after_jiffies(start + timeout) &&
 	       !(tda8083_readreg(state, 0x02) & 0x80))
 	{
 		msleep(50);
Signature · 1 line
2.7.4
author
#13 lore raw

PATCH v2 12/13 media: wl128x: use time_is_before_jiffies() instead of jiffies judgment

In reply to Qing Wang

From: Wang Qing <[email protected]>

It is better to use time_xxx() directly instead of jiffies judgment for understanding.

---
 drivers/media/radio/wl128x/fmdrv_common.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/media/radio/wl128x/fmdrv_common.c +2 -1
index 6142484d..a599d08
@@ -23,6 +23,7 @@
 #include <linux/firmware.h>
 #include <linux/module.h>
 #include <linux/nospec.h>
+#include <linux/jiffies.h>
 
 #include "fmdrv.h"
 #include "fmdrv_v4l2.h"
@@ -342,7 +343,7 @@ static void send_tasklet(struct tasklet_struct *t)
 		return;
 
 	/* Check, is there any timeout happened to last transmitted packet */
-	if ((jiffies - fmdev->last_tx_jiffies) > FM_DRV_TX_TIMEOUT) {
+	if (time_is_before_jiffies(fmdev->last_tx_jiffies + FM_DRV_TX_TIMEOUT)) {
 		fmerr("TX timeout occurred\n");
 		atomic_set(&fmdev->tx_cnt, 1);
 	}
Signature · 1 line
2.7.4
author
#14 lore raw

PATCH v2 13/13 media: vivid: use time_is_after_jiffies() instead of jiffies judgment

In reply to Qing Wang

From: Wang Qing <[email protected]>

It is better to use time_xxx() directly instead of jiffies judgment for understanding.

---
 drivers/media/test-drivers/vivid/vivid-kthread-cap.c   | 3 ++-
 drivers/media/test-drivers/vivid/vivid-kthread-out.c   | 3 ++-
 drivers/media/test-drivers/vivid/vivid-kthread-touch.c | 3 ++-
 drivers/media/test-drivers/vivid/vivid-sdr-cap.c       | 3 ++-
 4 files changed, 8 insertions(+), 4 deletions(-)
drivers/media/test-drivers/vivid/vivid-kthread-cap.c +2 -1
index 6baa046..295f4a3
@@ -18,6 +18,7 @@
 #include <linux/freezer.h>
 #include <linux/random.h>
 #include <linux/v4l2-dv-timings.h>
+#include <linux/jiffies.h>
 #include <asm/div64.h>
 #include <media/videobuf2-vmalloc.h>
 #include <media/v4l2-dv-timings.h>
@@ -893,7 +894,7 @@ static int vivid_thread_vid_cap(void *data)
 			next_jiffies_since_start = jiffies_since_start;
 
 		wait_jiffies = next_jiffies_since_start - jiffies_since_start;
-		while (jiffies - cur_jiffies < wait_jiffies &&
+		while (time_is_after_jiffies(cur_jiffies + wait_jiffies) &&
 		       !kthread_should_stop())
 			schedule();
 	}
drivers/media/test-drivers/vivid/vivid-kthread-out.c +2 -1
index b6d4316..13f737e
@@ -18,6 +18,7 @@
 #include <linux/freezer.h>
 #include <linux/random.h>
 #include <linux/v4l2-dv-timings.h>
+#include <linux/jiffies.h>
 #include <asm/div64.h>
 #include <media/videobuf2-vmalloc.h>
 #include <media/v4l2-dv-timings.h>
@@ -234,7 +235,7 @@ static int vivid_thread_vid_out(void *data)
 			next_jiffies_since_start = jiffies_since_start;
 
 		wait_jiffies = next_jiffies_since_start - jiffies_since_start;
-		while (jiffies - cur_jiffies < wait_jiffies &&
+		while (time_is_after_jiffies(cur_jiffies + wait_jiffies) &&
 		       !kthread_should_stop())
 			schedule();
 	}
drivers/media/test-drivers/vivid/vivid-kthread-touch.c +2 -1
index f065faae..8828243
@@ -5,6 +5,7 @@
  */
 
 #include <linux/freezer.h>
+#include <linux/jiffies.h>
 #include "vivid-core.h"
 #include "vivid-kthread-touch.h"
 #include "vivid-touch-cap.h"
@@ -134,7 +135,7 @@ static int vivid_thread_touch_cap(void *data)
 			next_jiffies_since_start = jiffies_since_start;
 
 		wait_jiffies = next_jiffies_since_start - jiffies_since_start;
-		while (jiffies - cur_jiffies < wait_jiffies &&
+		while (time_is_after_jiffies(cur_jiffies + wait_jiffies) &&
 		       !kthread_should_stop())
 			schedule();
 	}
drivers/media/test-drivers/vivid/vivid-sdr-cap.c +2 -1
index 59fd508..f82856b
@@ -17,6 +17,7 @@
 #include <media/v4l2-event.h>
 #include <media/v4l2-dv-timings.h>
 #include <linux/fixp-arith.h>
+#include <linux/jiffies.h>
 
 #include "vivid-core.h"
 #include "vivid-ctrls.h"
@@ -205,7 +206,7 @@ static int vivid_thread_sdr_cap(void *data)
 			next_jiffies_since_start = jiffies_since_start;
 
 		wait_jiffies = next_jiffies_since_start - jiffies_since_start;
-		while (jiffies - cur_jiffies < wait_jiffies &&
+		while (time_is_after_jiffies(cur_jiffies + wait_jiffies) &&
 		       !kthread_should_stop())
 			schedule();
 	}
Signature · 1 line
2.7.4
#15 lore raw
In reply to Qing Wang
Quoted 4 lines · Qing Wang

From: Wang Qing <[email protected]>

It is better to use time_is_xxx() directly instead of jiffies judgment for understanding.

Hi Wang,

"judgement" doesn't really make sense as a description to an English speaker. The following a commit desription (for all of these series) is probably going to be a bit more understable:

Use the helper function time_is_{before,after}_jiffies() to improve code readability.

Cheers,

- Ted

A message that is not in the archive (sent off-list or not yet received): AC2AdwCTE8eh*[email protected].@PFlnZmtnMG42UnZ2SllNSmFAbWl0LmVkdT4=

author
#17 lore raw

Quoted 12 lines
Quoted 5 lines · Qing Wang

From: Wang Qing <[email protected]>

It is better to use time_is_xxx() directly instead of jiffies judgment for understanding.

Hi Wang,

"judgement" doesn't really make sense as a description to an English speaker.  The following a commit desription (for all of these series) is probably going to be a bit more understable:

Quoted 6 lines

Use the helper function time_is_{before,after}_jiffies() to improve code readability.

Cheers,

                                               - Ted

I see, it will be corrected in V3.
I'll wait a few days if there are any other disagreements.

Thanks,
Qing