From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-11.9 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,INCLUDES_PATCH,MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id D18AEC43461 for ; Mon, 14 Sep 2020 16:10:12 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 8BB2820EDD for ; Mon, 14 Sep 2020 16:10:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1600099812; bh=yI0s//6TJSSQUXdVVQjhJfjWuCd2EdWI8qBQV3YQ9ew=; h=Date:From:To:Cc:Subject:References:In-Reply-To:List-ID:From; b=Im/+m8SsELWqo/wwh/8TN6wOselAug97LBHCUX+dGX+eAoVfPU9mCDFJjT6n7B8YW rupkvQqcmMq53mWRKqZgLUdCydCLV7aiEH7xAD8vSftpzlxbOvT7+1uyveefUj5l2K k9iXZkMeEbSzfxzNctn2EBQnN8RdgrQju9YpN98k= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726454AbgINQHn (ORCPT ); Mon, 14 Sep 2020 12:07:43 -0400 Received: from mail.kernel.org ([198.145.29.99]:60824 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726090AbgINQEE (ORCPT ); Mon, 14 Sep 2020 12:04:04 -0400 Received: from quaco.ghostprotocols.net (unknown [179.97.37.151]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 8D97920EDD; Mon, 14 Sep 2020 16:03:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1600099400; bh=yI0s//6TJSSQUXdVVQjhJfjWuCd2EdWI8qBQV3YQ9ew=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=mvDKO755QCkKry9ENHnmoI8y02lzf3KZzcp4AKASxezMRa7nTzHcSRTXfhUPHwa+R y6/hcVyRJQS8nujE1QM+0qNIN87zdInb49CWM+Rpek+Tmn1iJ9AfCB2uYmYicE0bkQ K6TmkcVKtYDC3XoxqpyvsFxxQvwoLBy1pcdTkOpU= Received: by quaco.ghostprotocols.net (Postfix, from userid 1000) id 7AB0840D3D; Mon, 14 Sep 2020 13:03:18 -0300 (-03) Date: Mon, 14 Sep 2020 13:03:18 -0300 From: Arnaldo Carvalho de Melo To: Namhyung Kim Cc: Jiri Olsa , lkml , Peter Zijlstra , Ingo Molnar , Mark Rutland , Alexander Shishkin , Michael Petlan , Song Liu , "Frank Ch. Eigler" , Ian Rogers , Stephane Eranian , Alexey Budankov , Andi Kleen , Adrian Hunter Subject: Re: [PATCH 05/26] perf tools: Add build_id__is_defined function Message-ID: <20200914160318.GG160517@kernel.org> References: <20200913210313.1985612-1-jolsa@kernel.org> <20200913210313.1985612-6-jolsa@kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Url: http://acmel.wordpress.com Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Em Mon, Sep 14, 2020 at 02:44:35PM +0900, Namhyung Kim escreveu: > On Mon, Sep 14, 2020 at 6:05 AM Jiri Olsa wrote: > > > > Adding build_id__is_defined helper to check build id > > is defined and is != zero build id. > > > > Signed-off-by: Jiri Olsa > > --- > > 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 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