From: Paolo Bonzini <pbonzini@redhat.com> To: Jing Zhang <jingzhangos@google.com>, KVM <kvm@vger.kernel.org>, KVMPPC <kvm-ppc@vger.kernel.org>, Sean Christopherson <seanjc@google.com>, Jim Mattson <jmattson@google.com>, Peter Shier <pshier@google.com>, Oliver Upton <oupton@google.com>, David Rientjes <rientjes@google.com>, David Matlack <dmatlack@google.com> Subject: Re: [PATCH v1 1/4] KVM: stats: Support linear and logarithmic histogram statistics Date: Wed, 28 Jul 2021 14:39:32 +0200 [thread overview] Message-ID: <8b6f442e-c8bd-d175-471e-6e28b4548c3e@redhat.com> (raw) In-Reply-To: <20210706180350.2838127-2-jingzhangos@google.com> On 06/07/21 20:03, Jing Zhang wrote: > +#define LINHIST_SIZE_SMALL 10 > +#define LINHIST_SIZE_MEDIUM 20 > +#define LINHIST_SIZE_LARGE 50 > +#define LINHIST_SIZE_XLARGE 100 > +#define LINHIST_BUCKET_SIZE_SMALL 10 > +#define LINHIST_BUCKET_SIZE_MEDIUM 100 > +#define LINHIST_BUCKET_SIZE_LARGE 1000 > +#define LINHIST_BUCKET_SIZE_XLARGE 10000 > + > +#define LOGHIST_SIZE_SMALL 8 > +#define LOGHIST_SIZE_MEDIUM 16 > +#define LOGHIST_SIZE_LARGE 32 > +#define LOGHIST_SIZE_XLARGE 64 > +#define LOGHIST_BASE_2 2 I'd prefer inlining all of these. For log histograms use 2 directly in STATS_DESC_LOG_HIST, since the update function below uses fls64. > > + */ > +void kvm_stats_linear_hist_update(u64 *data, size_t size, > + u64 value, size_t bucket_size) > +{ > + size_t index = value / bucket_size; > + > + if (index >= size) > + index = size - 1; > + ++data[index]; > +} > + Please make this function always inline, so that the compiler optimizes the division. Also please use array_index_nospec to clamp the index to the size, in case value comes from a memory access as well. Likewise for kvm_stats_log_hist_update. Paolo
WARNING: multiple messages have this Message-ID (diff)
From: Paolo Bonzini <pbonzini@redhat.com> To: Jing Zhang <jingzhangos@google.com>, KVM <kvm@vger.kernel.org>, KVMPPC <kvm-ppc@vger.kernel.org>, Sean Christopherson <seanjc@google.com>, Jim Mattson <jmattson@google.com>, Peter Shier <pshier@google.com>, Oliver Upton <oupton@google.com>, David Rientjes <rientjes@google.com>, David Matlack <dmatlack@google.com> Subject: Re: [PATCH v1 1/4] KVM: stats: Support linear and logarithmic histogram statistics Date: Wed, 28 Jul 2021 12:39:32 +0000 [thread overview] Message-ID: <8b6f442e-c8bd-d175-471e-6e28b4548c3e@redhat.com> (raw) In-Reply-To: <20210706180350.2838127-2-jingzhangos@google.com> On 06/07/21 20:03, Jing Zhang wrote: > +#define LINHIST_SIZE_SMALL 10 > +#define LINHIST_SIZE_MEDIUM 20 > +#define LINHIST_SIZE_LARGE 50 > +#define LINHIST_SIZE_XLARGE 100 > +#define LINHIST_BUCKET_SIZE_SMALL 10 > +#define LINHIST_BUCKET_SIZE_MEDIUM 100 > +#define LINHIST_BUCKET_SIZE_LARGE 1000 > +#define LINHIST_BUCKET_SIZE_XLARGE 10000 > + > +#define LOGHIST_SIZE_SMALL 8 > +#define LOGHIST_SIZE_MEDIUM 16 > +#define LOGHIST_SIZE_LARGE 32 > +#define LOGHIST_SIZE_XLARGE 64 > +#define LOGHIST_BASE_2 2 I'd prefer inlining all of these. For log histograms use 2 directly in STATS_DESC_LOG_HIST, since the update function below uses fls64. > > + */ > +void kvm_stats_linear_hist_update(u64 *data, size_t size, > + u64 value, size_t bucket_size) > +{ > + size_t index = value / bucket_size; > + > + if (index >= size) > + index = size - 1; > + ++data[index]; > +} > + Please make this function always inline, so that the compiler optimizes the division. Also please use array_index_nospec to clamp the index to the size, in case value comes from a memory access as well. Likewise for kvm_stats_log_hist_update. Paolo
next prev parent reply other threads:[~2021-07-28 12:39 UTC|newest] Thread overview: 56+ messages / expand[flat|nested] mbox.gz Atom feed top 2021-07-06 18:03 [PATCH v1 0/4] Linear and Logarithmic histogram statistics Jing Zhang 2021-07-06 18:03 ` Jing Zhang 2021-07-06 18:03 ` [PATCH v1 1/4] KVM: stats: Support linear and logarithmic " Jing Zhang 2021-07-06 18:03 ` Jing Zhang 2021-07-08 21:01 ` David Matlack 2021-07-08 21:01 ` David Matlack 2021-07-08 21:40 ` Jing Zhang 2021-07-08 21:40 ` Jing Zhang 2021-07-08 21:45 ` David Matlack 2021-07-08 21:45 ` David Matlack 2021-07-12 14:10 ` kernel test robot 2021-07-12 14:10 ` kernel test robot 2021-07-12 14:10 ` kernel test robot 2021-07-12 16:16 ` Jing Zhang 2021-07-12 16:16 ` Jing Zhang 2021-07-12 16:16 ` Jing Zhang 2021-07-12 18:53 ` kernel test robot 2021-07-12 18:53 ` kernel test robot 2021-07-12 18:53 ` kernel test robot 2021-07-28 12:39 ` Paolo Bonzini [this message] 2021-07-28 12:39 ` Paolo Bonzini 2021-07-30 17:31 ` Jing Zhang 2021-07-30 17:31 ` Jing Zhang 2021-07-06 18:03 ` [PATCH v1 2/4] KVM: stats: Update doc for " Jing Zhang 2021-07-06 18:03 ` Jing Zhang 2021-07-07 23:31 ` David Matlack 2021-07-07 23:31 ` David Matlack 2021-07-08 14:29 ` Jing Zhang 2021-07-08 14:29 ` Jing Zhang 2021-07-28 12:42 ` Paolo Bonzini 2021-07-28 12:42 ` Paolo Bonzini 2021-07-30 17:32 ` Jing Zhang 2021-07-30 17:32 ` Jing Zhang 2021-07-08 21:14 ` David Matlack 2021-07-08 21:14 ` David Matlack 2021-07-08 21:16 ` David Matlack 2021-07-08 21:16 ` David Matlack 2021-07-08 21:43 ` Jing Zhang 2021-07-08 21:43 ` Jing Zhang 2021-07-06 18:03 ` [PATCH v1 3/4] KVM: selftests: Add checks for histogram stats parameters Jing Zhang 2021-07-06 18:03 ` Jing Zhang 2021-07-08 21:26 ` David Matlack 2021-07-08 21:26 ` David Matlack 2021-07-06 18:03 ` [PATCH v1 4/4] KVM: stats: Add halt polling related histogram stats Jing Zhang 2021-07-06 18:03 ` Jing Zhang 2021-07-08 21:42 ` David Matlack 2021-07-08 21:42 ` David Matlack 2021-07-09 15:18 ` Jing Zhang 2021-07-09 15:18 ` Jing Zhang 2021-07-09 15:25 ` David Matlack 2021-07-09 15:25 ` David Matlack 2021-07-28 12:45 ` Paolo Bonzini 2021-07-28 12:45 ` Paolo Bonzini 2021-07-30 17:34 ` Jing Zhang 2021-07-30 17:34 ` Jing Zhang 2021-07-06 20:40 [PATCH v1 1/4] KVM: stats: Support linear and logarithmic histogram statistics kernel test robot
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=8b6f442e-c8bd-d175-471e-6e28b4548c3e@redhat.com \ --to=pbonzini@redhat.com \ --cc=dmatlack@google.com \ --cc=jingzhangos@google.com \ --cc=jmattson@google.com \ --cc=kvm-ppc@vger.kernel.org \ --cc=kvm@vger.kernel.org \ --cc=oupton@google.com \ --cc=pshier@google.com \ --cc=rientjes@google.com \ --cc=seanjc@google.com \ /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: linkBe 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.