All of lore.kernel.org
 help / color / mirror / Atom feed
From: Francois Romieu <romieu@fr.zoreil.com>
To: Thomas Osterried <thomas@osterried.de>
Cc: Bernard f6bvp <f6bvp@free.fr>, Eric Dumazet <edumazet@google.com>,
	linux-hams@vger.kernel.org,
	Thomas Osterried DL9SAU <thomas@x-berg.in-berlin.de>,
	netdev@vger.kernel.org
Subject: Re: rose timer t error displayed in /proc/net/rose
Date: Mon, 1 Aug 2022 17:44:33 +0200	[thread overview]
Message-ID: <Yuf04XIsXrQMJuUy@electric-eye.fr.zoreil.com> (raw)
In-Reply-To: <A9A8A0B7-5009-4FB0-9317-5033DE17E701@osterried.de>

[-- Attachment #1: Type: text/plain, Size: 1917 bytes --]

Thomas Osterried <thomas@osterried.de> :
[...]
> 1. why do you check for pending timer anymore?

s/do/don't/ ?

I don't check for pending timer because:
- the check is racy
- jiffies_delta_to_clock_t maxes negative delta to zero

> 2. I'm not really sure what value jiffies_delta_to_clock_t() returns. jiffies / HZ?
>    jiffies_delta_to_clock_t() returns clock_t.

I completely messed this part :o/

clock_t relates to USER_HZ like jiffies does to HZ.

[don't break the ax25]

Sure, we are in violent agreement here.

[...]
> 1. I expect rose->timer to be restarted soon. If it does not happen, is there a bug?

The relevant rose state in Bernard's sample was ROSE_STATE_2.

net/rose/rose_timer.c::rose_timer_expiry would had called
rose_disconnect(sk, ETIMEDOUT, -1, -1) so there should not
be any timer restart (afaiu, etc.).

[...]
>    => Negative may be handled due to Francois' patch now correctly.
> delta as signed long may be negative. max(0L, -nnnn) sould result to 0L.
>    This would result to 0. Perhaps proven by Francois, because he used this function and achieved a correct display of that idle value. Francois, am I correct, is "0" really displayed?

I must confess that I was not terribly professional this morning past 2AM.

The attached snippet illustrates the behavior wrt negative values
(make; insmod foo.ko ; sleep 1; rmmod foo.ko; dmesg | tail -n 2).
It also illustrates that I got the unit wrong.

This should be better:

diff --git a/net/ax25/ax25_timer.c b/net/ax25/ax25_timer.c
index 85865ebfdfa2..3c94e5a2d098 100644
--- a/net/ax25/ax25_timer.c
+++ b/net/ax25/ax25_timer.c
@@ -108,10 +108,9 @@ int ax25_t1timer_running(ax25_cb *ax25)
 
 unsigned long ax25_display_timer(struct timer_list *timer)
 {
-	if (!timer_pending(timer))
-		return 0;
+	long delta = timer->expires - jiffies;
 
-	return timer->expires - jiffies;
+	return max(0L, delta);
 }
 
 EXPORT_SYMBOL(ax25_display_timer);


[-- Attachment #2: Makefile --]
[-- Type: text/plain, Size: 129 bytes --]

obj-m := foo.o

KDIR := /lib/modules/$(shell uname -r)/build
PWD  := $(shell pwd)

default:
	$(MAKE) -C $(KDIR) M=$(PWD) modules

[-- Attachment #3: foo.c --]
[-- Type: text/plain, Size: 512 bytes --]

#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/init.h>

#include <linux/jiffies.h>

static unsigned long expires;

static void bar(void)
{
	long delta = expires - jiffies;

	printk(KERN_INFO "%lu %lu %lx\n", jiffies_delta_to_clock_t(delta),
	       jiffies_delta_to_clock_t(jiffies), delta);
}

static int __init foo_start(void)
{
	expires = jiffies;

	bar();

	return 0;
}

static void __exit foo_end(void)
{
	bar();
}

module_init(foo_start);
module_exit(foo_end);

MODULE_LICENSE("GPL");

  parent reply	other threads:[~2022-08-01 15:44 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-07-30 15:08 rose timer t error displayed in /proc/net/rose Bernard f6bvp
2022-08-01  0:39 ` Francois Romieu
2022-08-01  8:06   ` Thomas Osterried
2022-08-01  9:19     ` Bernard f6bvp
2022-08-01 15:44     ` Francois Romieu [this message]
2022-08-01 19:06       ` Thomas Osterried
2022-08-01 19:33       ` Bernard f6bvp
2022-08-07 18:04       ` [PATCH] AX25 rose_call - replacing carriage return by newlines f6bvp
2022-08-07 18:21       ` Resend : " f6bvp
     [not found]         ` <ABFC096C-8F65-49C9-8BB9-7B75B3CE30B7@osterried.de>
2022-08-08 12:31           ` f6bvp
2022-08-01  8:54   ` rose timer t error displayed in /proc/net/rose Bernard f6bvp
2022-08-01 10:43   ` Bernard f6bvp

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=Yuf04XIsXrQMJuUy@electric-eye.fr.zoreil.com \
    --to=romieu@fr.zoreil.com \
    --cc=edumazet@google.com \
    --cc=f6bvp@free.fr \
    --cc=linux-hams@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=thomas@osterried.de \
    --cc=thomas@x-berg.in-berlin.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.