From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-wr1-f45.google.com (mail-wr1-f45.google.com [209.85.221.45]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 1F3EE10F1 for ; Thu, 19 Feb 2026 10:39:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.45 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1771497542; cv=none; b=MQvV+mJwJnRAliTwrPSToK13F8MLExJwB/RxgeprYdnIgDYm4zz8Lk+lg+ozryKmGnbVNnE4jLiAM+buqTH6MC3NNqoCR1mipKWJDs06rAYO/NCcfvgCE4zLBDbMsVVn9TzWQakGYKuGpjI8lOgqgwdTstGMjwy9m5Mr0K2TMyw= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1771497542; c=relaxed/simple; bh=Kym04Oo3V+mA3kzh3DiwjhAMsB/Z5CxmPahrisXhs3M=; h=Message-ID:Date:MIME-Version:Subject:From:To:Cc:References: In-Reply-To:Content-Type; b=AZYijGBR4TRwjJ5KTIQY9YHCl0ECMUqgYBw8VNLyLnGCAfrsaxsbTwcIKBtIMruqe0s8Dv8UmoJpLan/3oNQYfuA+tjJY+vwY/hX4ZPQW7O8JFzSk8mhvyv5zSeJr4KEGd7AGkFKw4ORrYcdYYZoVqO0qJFiKuTQG/3p5xfOZw8= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org; spf=pass smtp.mailfrom=linaro.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b=kYZ7ZXWQ; arc=none smtp.client-ip=209.85.221.45 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linaro.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="kYZ7ZXWQ" Received: by mail-wr1-f45.google.com with SMTP id ffacd0b85a97d-43638a3330dso658178f8f.0 for ; Thu, 19 Feb 2026 02:39:00 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1771497539; x=1772102339; darn=vger.kernel.org; h=content-transfer-encoding:in-reply-to:content-language:references :cc:to:from:subject:user-agent:mime-version:date:message-id:from:to :cc:subject:date:message-id:reply-to; bh=X8iDLK3qN6o4TbYoP42I01clZFWdxZSpMrTnquDLRYc=; b=kYZ7ZXWQIoMnT9c9b4rs5zhyp/sSlNe57WLGPb+vX2TTRzbRy2j8I93XSRwFbB6t8H ETF0/Nr/iQEgZpqyFUFbI9hoMLVSn+WzpcumF7zJPqVktvyzhAtBbjp0vEnpHF9X4CNk eEhEdX3dFzFJ4eY6OpjtXr03qjxfO8NQtIN+4FgQ0HIYbVdYuiBLsJ7bCCvsLBPpgIw1 WwRfWlI1Zfxq+oEyFmOcTH4NdnlW7ysYhUi0wJpx23TwnUYT0LtO0fiNwIqhEhNRFjPU P2k4m+XOiwwsDASiU+ni4VKUykb9aoh6bnO3dG9Np+PlqMZp7dv6MQxMz+UdwPEElxbF LE0w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1771497539; x=1772102339; h=content-transfer-encoding:in-reply-to:content-language:references :cc:to:from:subject:user-agent:mime-version:date:message-id:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=X8iDLK3qN6o4TbYoP42I01clZFWdxZSpMrTnquDLRYc=; b=ZceBiaUP589zQk282C26SythcewgGRbowyGQVEjP2/N5fAE63VX2nMwvX2A9WZv9Q2 bhCdnqRtE9BE0sANyjmCSlJAWp8tBuHk/VmSxb/jxgy3kI2E7rSmeFlt1sdTsJzDDXAy ywFL/yj9pUtrLZxg2EFFQFRgpbxy7HhkrACEbwkQMdYOil6GNJ8pNUgExtjkCL3Wj+fu M1wENAVHtPvLIiHXtX5YdqibY4cwtrUqbqC8+TrNMEocUQjp/QnTvidwWw5q9Gat0EBl Cr9u5XBgh6E4jAdP5FZLWFXYWYTirOQZ77s8zguEqQiUfktz5sH57acTFONZ8+o+Upn9 J47g== X-Forwarded-Encrypted: i=1; AJvYcCUj6SqUmVCzk/rDJq5HQ+nQzCwgo46bWvKmn6sn8TfelrK0uJfU9+P6XJkkD0SffntvaxAAiijzCzPmKLU=@vger.kernel.org X-Gm-Message-State: AOJu0YxOZ6fw5xfbrL7yl4jGL6TP93kqSRZe5Uz5AcodpR7ERwhHP0vn +XK4wi7DCZV0/BhO6b2kRPWWpOJlrOuC+BJYakKbB9pV9GQbrm/HMxamdQ3SUH6ArLA= X-Gm-Gg: AZuq6aKiqANm1EHfwuR1grJcBhlO1Z0Do5Ci2k8owXqzNPxNnxwpK9mWQBjRQh4fO+Z uhPpzupH/RzxAsuL5Sd4te8l19spel7yUij+j4xNNkP63tqeav3cBiq8QzM7o/rmrWajczgGtAC /IBMUVk/wJG+zQQxQBVrKMw/pO+6WIW0J72tou8MiezWOHdJta/TmEueZSg8nf11Tfrm2TFxRxp ti/VdsdSewWeM9XruwqV+pEFZkucBMv+3vwtwytCOxilzVBBf8wnV3Nl6DJhaYSAIIBjZe2CHLa CBcflw/g7Npf+aeQP2dhe2x0dhF0XYmeJJanOIvU+lhS6wJVMbVc1zPREWHtBfoRFuvkav3auHV FgdR+DPvlb1tIsnxQduZ089qyQeky0SQkAl7lZOtNiXCepCww+30e8kLPrf/EruLMPYXLmfeffz DX6mYw3KH3iZb0bsMIClV6sWnmzPzw X-Received: by 2002:a5d:5850:0:b0:437:8f37:882 with SMTP id ffacd0b85a97d-4379db93a97mr33803414f8f.33.1771497539359; Thu, 19 Feb 2026 02:38:59 -0800 (PST) Received: from [192.168.1.3] ([185.48.77.170]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-43796a6c1bfsm49110068f8f.13.2026.02.19.02.38.58 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 19 Feb 2026 02:38:58 -0800 (PST) Message-ID: Date: Thu, 19 Feb 2026 10:38:57 +0000 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v2 1/2] perf bench: Fix initialization of union From: James Clark To: Namhyung Kim , Arnaldo Carvalho de Melo , Ian Rogers , Leo Yan Cc: Jiri Olsa , Adrian Hunter , Peter Zijlstra , Ingo Molnar , LKML , linux-perf-users@vger.kernel.org References: <20260219004417.188434-1-namhyung@kernel.org> Content-Language: en-US In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit On 19/02/2026 10:36 am, James Clark wrote: > > > On 19/02/2026 12:44 am, Namhyung Kim wrote: >> Recent compilers don't initialize all members (or the largest member) in >> an union.  Instead it seems to set the first member only.  So some perf >> bench output shows invalid numbers like below on my system with GCC 15. > > I couldn't find V1 of this so I wasn't sure if it was discussed already, > but wasn't the plan to fix this with a compiler option: > > https://lore.kernel.org/linux-perf-users/20250319110454.3230687-1- > leo.yan@arm.com/ > > and > > https://lore.kernel.org/linux-perf-users/20250320105235.3498106-1- > leo.yan@arm.com/ > > Oh I see V1 was only the second patch, that's why I couldn't find it. >> >> Before: >>    $ perf bench mem mmap >>    # Running 'mem/mmap' benchmark: >>    # function 'demand' (Demand loaded mmap()) >>    # Copying 1MB bytes ... >> >>           0.011127 bytes/sec >>    # function 'populate' (Eagerly populated mmap()) >>    # Copying 1MB bytes ... >> >>           0.011127 bytes/sec >> >> After: >>    $ perf bench mem mmap >>    # Running 'mem/mmap' benchmark: >>    # function 'demand' (Demand loaded mmap()) >>    # Copying 1MB bytes ... >> >>           2.209417 GB/sec >>    # function 'populate' (Eagerly populated mmap()) >>    # Copying 1MB bytes ... >> >>           7.875504 GB/sec >> >> Because the first member of bench_clock is u64 ('cycles'), the default >> struct timeval wasn't fully initialized.  Let's use memset to reset the >> whole memory. >> >> Signed-off-by: Namhyung Kim >> --- >>   tools/perf/bench/mem-functions.c | 3 ++- >>   1 file changed, 2 insertions(+), 1 deletion(-) >> >> diff --git a/tools/perf/bench/mem-functions.c b/tools/perf/bench/mem- >> functions.c >> index 2908a3a796c932d0..676c8d18f4c2e259 100644 >> --- a/tools/perf/bench/mem-functions.c >> +++ b/tools/perf/bench/mem-functions.c >> @@ -193,9 +193,10 @@ static void __bench_mem_function(struct >> bench_mem_info *info, struct bench_param >>   { >>       const struct function *r = &info->functions[r_idx]; >>       double result_bps = 0.0; >> -    union bench_clock rt = { 0 }; >> +    union bench_clock rt; >>       void *src = NULL, *dst = NULL; >> +    memset(&rt, 0, sizeof(rt)); >>       printf("# function '%s' (%s)\n", r->name, r->desc); >>       if (r->fn.init && r->fn.init(info, p, &src, &dst)) >