linux-arm-kernel.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
From: "Boy Wu (吳勃誼)" <Boy.Wu@mediatek.com>
To: "tj@kernel.org" <tj@kernel.org>
Cc: "boris@bur.io" <boris@bur.io>,
	"linux-block@vger.kernel.org" <linux-block@vger.kernel.org>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
	"cgroups@vger.kernel.org" <cgroups@vger.kernel.org>,
	"linux-mediatek@lists.infradead.org"
	<linux-mediatek@lists.infradead.org>,
	"axboe@kernel.dk" <axboe@kernel.dk>,
	"Iverlin Wang (王苳霖)" <Iverlin.Wang@mediatek.com>,
	"josef@toxicpanda.com" <josef@toxicpanda.com>,
	"linux-arm-kernel@lists.infradead.org"
	<linux-arm-kernel@lists.infradead.org>,
	"matthias.bgg@gmail.com" <matthias.bgg@gmail.com>,
	"angelogioacchino.delregno@collabora.com"
	<angelogioacchino.delregno@collabora.com>
Subject: Re: [PATCH v3] blk-cgroup: Replace u64 sync with spinlock for iostat update
Date: Wed, 17 Jul 2024 04:09:53 +0000	[thread overview]
Message-ID: <1b19b68adb34410bf6dc8fd3f50e4b82c1a014e4.camel@mediatek.com> (raw)
In-Reply-To: <5560c690cc6de67139a9b2e45c7a11938b70fc58.camel@mediatek.com>

On Wed, 2024-07-17 at 11:44 +0800, Boy.Wu wrote:
> 
> I think there is another way to fix it. Maybe we should address the
> root cause, which is that u64_stats_update_begin_irqsave
> and u64_stats_update_end_irqrestore do not protect the seqcount in 32
> bit SMP systems. This can be fix by the following change.
> 
> diff --git a/include/linux/u64_stats_sync.h
> b/include/linux/u64_stats_sync.h
> index 46040d66334a..94dd74b4fb2c 100644
> --- a/include/linux/u64_stats_sync.h
> +++ b/include/linux/u64_stats_sync.h
> @@ -64,6 +64,7 @@
>  struct u64_stats_sync {
>  #if BITS_PER_LONG == 32
>         seqcount_t      seq;
> +       spinlock_t      spinlock;
>  #endif
>  };
> 
> @@ -138,6 +139,7 @@ static inline void u64_stats_inc(u64_stats_t *p)
>  static inline void u64_stats_init(struct u64_stats_sync *syncp)
>  {
>         seqcount_init(&syncp->seq);
> +       spin_lock_init(&syncp->spinlock)
>  }
> 
>  static inline void __u64_stats_update_begin(struct u64_stats_sync
> *syncp)
> @@ -191,6 +193,7 @@ static inline unsigned long
> u64_stats_update_begin_irqsave(struct u64_stats_sync
>  {
>         unsigned long flags = __u64_stats_irqsave();
> 
> +       spin_lock_irq(&syncp->spinlock);
>         __u64_stats_update_begin(syncp);
>         return flags;
>  }
> @@ -199,6 +202,7 @@ static inline void
> u64_stats_update_end_irqrestore(struct u64_stats_sync *syncp,
>                                                    unsigned long
> flags)
>  {
>         __u64_stats_update_end(syncp);
> +       spin_unlock_irq(&syncp->spinlock);
>         __u64_stats_irqrestore(flags);
>  }
> 
> --
> boy.wu
> 

Never mind, there is a usage in u64_stats_sync.h

 * Usage :
 *
 * Stats producer (writer) should use following template granted it
already got
 * an exclusive access to counters (a lock is already taken, or per cpu
 * data is used [in a non preemptable context])
 *
 *   spin_lock_bh(...) or other synchronization to get exclusive access
 *   ...
 *   u64_stats_update_begin(&stats->syncp);
 *   u64_stats_add(&stats->bytes64, len); // non atomic operation
 *   u64_stats_inc(&stats->packets64);    // non atomic operation
 *   u64_stats_update_end(&stats->syncp);

--
boy.wu


  reply	other threads:[~2024-07-17  4:10 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-07-16  7:52 [PATCH v3] blk-cgroup: Replace u64 sync with spinlock for iostat update boy.wu
2024-07-16 21:13 ` Tejun Heo
2024-07-17  2:25   ` Boy Wu (吳勃誼)
2024-07-17  3:44     ` Boy Wu (吳勃誼)
2024-07-17  4:09       ` Boy Wu (吳勃誼) [this message]
2024-07-17 16:55         ` tj
2024-07-17 17:37           ` Waiman Long
2024-07-17 17:40             ` tj
2024-07-17 18:18               ` Waiman Long
2024-07-17 18:24                 ` tj
2024-07-17 18:55                   ` Waiman Long
2024-07-17 18:57                     ` tj
2024-07-18  1:21           ` Boy Wu (吳勃誼)
2024-07-18  1:27             ` tj

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=1b19b68adb34410bf6dc8fd3f50e4b82c1a014e4.camel@mediatek.com \
    --to=boy.wu@mediatek.com \
    --cc=Iverlin.Wang@mediatek.com \
    --cc=angelogioacchino.delregno@collabora.com \
    --cc=axboe@kernel.dk \
    --cc=boris@bur.io \
    --cc=cgroups@vger.kernel.org \
    --cc=josef@toxicpanda.com \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-block@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mediatek@lists.infradead.org \
    --cc=matthias.bgg@gmail.com \
    --cc=tj@kernel.org \
    /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;
as well as URLs for NNTP newsgroup(s).