From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752455AbdGMOxJ (ORCPT ); Thu, 13 Jul 2017 10:53:09 -0400 Received: from mga06.intel.com ([134.134.136.31]:17882 "EHLO mga06.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751201AbdGMOxI (ORCPT ); Thu, 13 Jul 2017 10:53:08 -0400 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.40,354,1496127600"; d="scan'208";a="1194997642" Subject: Re: [PATCH v8 2/7] perf/x86/intel: Record branch type To: Peter Zijlstra Cc: acme@kernel.org, jolsa@kernel.org, mingo@redhat.com, alexander.shishkin@linux.intel.com, mpe@ellerman.id.au, Linux-kernel@vger.kernel.org, ak@linux.intel.com, kan.liang@intel.com, yao.jin@intel.com References: <1499947459-4527-1-git-send-email-yao.jin@linux.intel.com> <1499947459-4527-3-git-send-email-yao.jin@linux.intel.com> <20170713143150.ceby42dokdeagxas@hirez.programming.kicks-ass.net> From: "Jin, Yao" Message-ID: <328f38ee-edc4-33a5-5ebe-7ed2dc19d9a4@linux.intel.com> Date: Thu, 13 Jul 2017 22:53:04 +0800 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:52.0) Gecko/20100101 Thunderbird/52.2.1 MIME-Version: 1.0 In-Reply-To: <20170713143150.ceby42dokdeagxas@hirez.programming.kicks-ass.net> Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit Content-Language: en-US Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 7/13/2017 10:31 PM, Peter Zijlstra wrote: > On Thu, Jul 13, 2017 at 08:04:14PM +0800, Jin Yao wrote: >> +#define X86_BR_TYPE_MAP_MAX 16 >> + >> +static int >> +common_branch_type(int type) >> +{ >> + int i, mask; >> + const int branch_map[X86_BR_TYPE_MAP_MAX] = { >> + PERF_BR_CALL, /* X86_BR_CALL */ >> + PERF_BR_RET, /* X86_BR_RET */ >> + PERF_BR_SYSCALL, /* X86_BR_SYSCALL */ >> + PERF_BR_SYSRET, /* X86_BR_SYSRET */ >> + PERF_BR_UNKNOWN, /* X86_BR_INT */ >> + PERF_BR_UNKNOWN, /* X86_BR_IRET */ >> + PERF_BR_COND, /* X86_BR_JCC */ >> + PERF_BR_UNCOND, /* X86_BR_JMP */ >> + PERF_BR_UNKNOWN, /* X86_BR_IRQ */ >> + PERF_BR_IND_CALL, /* X86_BR_IND_CALL */ >> + PERF_BR_UNKNOWN, /* X86_BR_ABORT */ >> + PERF_BR_UNKNOWN, /* X86_BR_IN_TX */ >> + PERF_BR_UNKNOWN, /* X86_BR_NO_TX */ >> + PERF_BR_CALL, /* X86_BR_ZERO_CALL */ >> + PERF_BR_UNKNOWN, /* X86_BR_CALL_STACK */ >> + PERF_BR_IND, /* X86_BR_IND_JMP */ >> + }; >> + >> + type >>= 2; /* skip X86_BR_USER and X86_BR_KERNEL */ > >> + mask = ~(~0 << 1); > OCC worthy means of writing: 1 Yes, mask = 1. I just want to represent the bit 0 of mask is 1. >> + >> + for (i = 0; i < X86_BR_TYPE_MAP_MAX; i++) { >> + if (type & mask) >> + return branch_map[i]; >> + >> + type >>= 1; >> + } > That is some of the more confused code I've seen in a while :/ > > if (type) > return branch_map[__ffs(type)]; > > is what you meant to write, no? Not write, I just want to return the element of branch_map[]. The input type is one of X86_BR and the X86_BR is: X86_BR_CALL = 1 << 2, /* call */ X86_BR_RET = 1 << 3, /* return */ X86_BR_SYSCALL = 1 << 4, /* syscall */ X86_BR_SYSRET = 1 << 5, /* syscall return */ X86_BR_INT = 1 << 6, /* sw interrupt */ X86_BR_IRET = 1 << 7, /* return from interrupt */ X86_BR_JCC = 1 << 8, /* conditional */ X86_BR_JMP = 1 << 9, /* jump */ X86_BR_IRQ = 1 << 10,/* hw interrupt or trap or fault */ X86_BR_IND_CALL = 1 << 11,/* indirect calls */ X86_BR_ABORT = 1 << 12,/* transaction abort */ X86_BR_IN_TX = 1 << 13,/* in transaction */ X86_BR_NO_TX = 1 << 14,/* not in transaction */ X86_BR_ZERO_CALL = 1 << 15,/* zero length call */ X86_BR_CALL_STACK = 1 << 16,/* call stack */ X86_BR_IND_JMP = 1 << 17,/* indirect jump */ Lookup the table to get the common branch type. Sorry, what is the __ffs()? Thanks Jin Yao >> + >> + return PERF_BR_UNKNOWN; >> +}