lkml.org 
[lkml]   [2020]   [Sep]   [14]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: [PATCH 05/26] perf tools: Add build_id__is_defined function
Em Mon, Sep 14, 2020 at 02:44:35PM +0900, Namhyung Kim escreveu:
> On Mon, Sep 14, 2020 at 6:05 AM Jiri Olsa <jolsa@kernel.org> wrote:
> >
> > Adding build_id__is_defined helper to check build id
> > is defined and is != zero build id.
> >
> > Signed-off-by: Jiri Olsa <jolsa@kernel.org>
> > ---
> > tools/perf/util/build-id.c | 11 +++++++++++
> > tools/perf/util/build-id.h | 1 +
> > 2 files changed, 12 insertions(+)
> >
> > diff --git a/tools/perf/util/build-id.c b/tools/perf/util/build-id.c
> > index 31207b6e2066..bdee4e08e60d 100644
> > --- a/tools/perf/util/build-id.c
> > +++ b/tools/perf/util/build-id.c
> > @@ -902,3 +902,14 @@ bool perf_session__read_build_ids(struct perf_session *session, bool with_hits)
> >
> > return ret;
> > }
> > +
> > +bool build_id__is_defined(const u8 *build_id)
> > +{
> > + static u8 zero[BUILD_ID_SIZE];
> > + int err = 0;
> > +
> > + if (build_id)
> > + err = memcmp(build_id, &zero, BUILD_ID_SIZE);
> > +
> > + return err ? true : false;
> > +}

> I think this is a bit confusing.. How about this?

> bool ret = false;
> if (build_id)
> ret = memcmp(...);
> return ret;

> Or, it can be a oneliner..

Yeah.

I was curious about if the kernel lib has something to ask if a range of
memory is zeroed, and there is this:

static bool is_zeroed(void *from, size_t size)
{
return memchr_inv(from, 0x0, size) == NULL;
}

commit 798248206b59acc6e1238c778281419c041891a7
Author: Akinobu Mita <akinobu.mita@gmail.com>
Date: Mon Oct 31 17:08:07 2011 -0700

lib/string.c: introduce memchr_inv()

memchr_inv() is mainly used to check whether the whole buffer is filled
with just a specified byte.

The function name and prototype are stolen from logfs and the
implementation is from SLUB.

---

Some usage in drivers/nvme/target/admin-cmd.c

+static void nvmet_execute_identify_desclist(struct nvmet_req *req)
+{
+ struct nvmet_ns *ns;
+ u16 status = 0;
+ off_t off = 0;
+
+ ns = nvmet_find_namespace(req->sq->ctrl, req->cmd->identify.nsid);
+ if (!ns) {
+ status = NVME_SC_INVALID_NS | NVME_SC_DNR;
+ goto out;
+ }
+
+ if (memchr_inv(&ns->uuid, 0, sizeof(ns->uuid))) {
+ status = nvmet_copy_ns_identifier(req, NVME_NIDT_UUID,
+ NVME_NIDT_UUID_LEN,
+ &ns->uuid, &off);
+ if (status)
+ goto out_put_ns;
+ }

More:

[acme@five perf]$ find arch/ -type f | xargs grep memchr_inv
arch/x86/kernel/fpu/xstate.c: if (memchr_inv(hdr->reserved, 0, sizeof(hdr->reserved)))
arch/x86/mm/init_64.c: if (!memchr_inv(page_addr, PAGE_INUSE, PAGE_SIZE)) {
arch/x86/mm/init_64.c: if (!memchr_inv(page_addr, PAGE_INUSE,
arch/x86/mm/init_64.c: if (!memchr_inv(page_addr, PAGE_INUSE,
arch/s390/mm/vmem.c: return !memchr_inv(page, PAGE_UNUSED, PMD_SIZE);
arch/powerpc/platforms/powermac/nvram.c: if (memchr_inv(base, 0xff, NVRAM_SIZE)) {
arch/powerpc/platforms/powermac/nvram.c: if (memchr_inv(base, 0xff, NVRAM_SIZE)) {
[acme@five perf]$

- Arnaldo

\
 
 \ /
  Last update: 2020-09-14 18:08    [W:0.448 / U:0.088 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site