Received: by 2002:aa6:da0e:0:b029:115:a171:fe4c with SMTP id z14csp1254427lkb; Wed, 7 Jul 2021 02:38:34 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyYSGX5OyHjbn8sqykn68pZ08379NhxfpX5KljFMIO3HvqFE6nS1JIqSDwiF0dTt1TZDThc X-Received: by 2002:a05:6638:d4d:: with SMTP id d13mr11852733jak.140.1625650714284; Wed, 07 Jul 2021 02:38:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1625650714; cv=none; d=google.com; s=arc-20160816; b=ROZYKMTWViGenz8tFE/2zU0azcGySUT2CmMF/M3/814fdK0jY7lQS84pPleJ+0vB3X QY0U60zuRB2SA5hGKGv4scF1F+WD/MgZarvkn3DZ2DHT80R5l9O5j/Zefdwc0uD5zNGe oJ4WPngM6FA21XFlQFzbzU/AemWMWNYMcXfs2+/eE1ptNQHgLrRQ2Zhu4qOOoC+BqGfh ISAJ+b5gZ2wFHa0CHY4uSRK4NxxohNAg25a1OrZyK/02UiOx3CUZoVydYuwYRtiqQJXy FqKwYHMaSkL0Bmvmeoxeh+0rFaHsJx3Dt0OxgRS1g7EZGwrcSpbXIMp0NmnMLsOWJa2D Lc3A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=deNkM43HVrzzox3/O3Vf0dj4Yd0AsDTSqL5zXDoRHrQ=; b=ndM7J6v9Bm5+TcL2S0GoliMhadpx6dy6zexXwPo+a6ztbUw0plOc6nW/3EsQnccWT1 P+/Cj5W6S0iCicNDpqR79mtRxu6x4YS8b+ZZxLXgSZ2KsK5Fs3v9NDpvodQZimlAAUc8 d90mac1Wg+CdDbadNZ2KbXksCo+w+f3CLIp3iGQphygb+wmZkIIlvVgLl1JjwQ3aPNlh dwFSXgasji83DQPKbmx31ekdf+zPx4lFiH4gbz/Slqw+gRm5gWPxXXe+xxQfqg8Mhx9S RdJAJqY32WEtLVJB8XM/nwg2P0HHxmmlZc1PRFW4vfpZ7VBJ4Mhu6qjyEtDufDlVCpWf h4bA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=j9VDxZYo; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id w17si18383145ilj.116.2021.07.07.02.38.21; Wed, 07 Jul 2021 02:38:34 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=j9VDxZYo; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230478AbhGGJkX (ORCPT + 99 others); Wed, 7 Jul 2021 05:40:23 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59856 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230429AbhGGJkW (ORCPT ); Wed, 7 Jul 2021 05:40:22 -0400 Received: from mail-lf1-x12e.google.com (mail-lf1-x12e.google.com [IPv6:2a00:1450:4864:20::12e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8F5E0C061574 for ; Wed, 7 Jul 2021 02:37:42 -0700 (PDT) Received: by mail-lf1-x12e.google.com with SMTP id u18so2963767lff.9 for ; Wed, 07 Jul 2021 02:37:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=deNkM43HVrzzox3/O3Vf0dj4Yd0AsDTSqL5zXDoRHrQ=; b=j9VDxZYoMcJ9CKs8I3W2QKoYU1FWDBYA+P9rAg5P0WjqmAHy8IkqVJz/4Te+OPOZaV HQUZO7OaFwMr/zN/a3f/ofcSSv54xCFaSH3jh4V7pMaeJqiXIY3SO6c/aoBBBT1hiZqr Zi7TwZY30QNnzaXazHbvKjHZqBr3+FWqrCa7qfoAjBm13MHLW2zOqEAjvQvcKqqUBdb7 hh8c7IPUt76uko5dYfti2tcsXmjK3AkxBneuK3fP9INu8Gyxg1N/MTmsFlzEMj9P02/q 8nkp5FPHlF4tfg/UoLTq6OFYLgyBu9JfAd1NZNDEt6jKJEpIbjXEuJE/h6MJ7AE/6cr2 Y5gg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=deNkM43HVrzzox3/O3Vf0dj4Yd0AsDTSqL5zXDoRHrQ=; b=Gstm4h+j/ffVxHxyaEHiVDqKh9cH2DUkrlov1s5u/wAbqzMv3bW5przRwJg8ZwcPvg Eom/3U8E0gLl0ASro3XBt1P3sQMm6V6fyyANbKgEi38OF3jf/EC50hll7HwoxZIM6Lpk C/o9Y4y+B6oStYFoQx3CJ02qNU3fBjgObeQmWkfSWYxCPW2wbKa7UCKxC6iNAJgQGiDx rYMa1MaXbyoRqzdCJUCeDWDzAKGJU23fei4588c1d4dgLA07rAW1odTOU19zb7h7XamA 69YN9Syedn7zMQ/9+ZeMBwWYzaBWLOQfuLni5izGcT2bB8byclQfPAbifY6ItMExMpl+ f4dA== X-Gm-Message-State: AOAM5309h1X4vNWi4onOf13C702nZidOcVMcFwS/o0wD5KMUcy/gvRL6 P+xM/nBi7a3YmSpoY4Q0z+JeCeSJ7pOuA8aQnVJYJA== X-Received: by 2002:a05:6512:3d11:: with SMTP id d17mr6100684lfv.254.1625650660885; Wed, 07 Jul 2021 02:37:40 -0700 (PDT) MIME-Version: 1.0 References: <20210625152603.25960-1-lukasz.luba@arm.com> <20210625152603.25960-2-lukasz.luba@arm.com> <2f43b211-da86-9d48-4e41-1c63359865bb@arm.com> In-Reply-To: <2f43b211-da86-9d48-4e41-1c63359865bb@arm.com> From: Vincent Guittot Date: Wed, 7 Jul 2021 11:37:29 +0200 Message-ID: Subject: Re: [PATCH 1/3] sched/fair: Prepare variables for increased precision of EAS estimated energy To: Lukasz Luba Cc: linux-kernel , Chris Redpath , Dietmar Eggemann , Morten Rasmussen , Quentin Perret , "open list:THERMAL" , Peter Zijlstra , "Rafael J. Wysocki" , Viresh Kumar , Ingo Molnar , Juri Lelli , Steven Rostedt , segall@google.com, Mel Gorman , Daniel Bristot de Oliveira , CCj.Yeh@mediatek.com Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, 7 Jul 2021 at 10:23, Lukasz Luba wrote: > > > > On 7/7/21 9:00 AM, Vincent Guittot wrote: > > On Wed, 7 Jul 2021 at 09:49, Lukasz Luba wrote: > >> > >> > >> > >> On 7/7/21 8:07 AM, Vincent Guittot wrote: > >>> On Fri, 25 Jun 2021 at 17:26, Lukasz Luba wrote: > >>>> > >>>> The Energy Aware Scheduler (EAS) tries to find best CPU for a waking up > >>>> task. It probes many possibilities and compares the estimated energy values > >>>> for different scenarios. For calculating those energy values it relies on > >>>> Energy Model (EM) data and em_cpu_energy(). The precision which is used in > >>>> EM data is in milli-Watts (or abstract scale), which sometimes is not > >>>> sufficient. In some cases it might happen that two CPUs from different > >>>> Performance Domains (PDs) get the same calculated value for a given task > >>>> placement, but in more precised scale, they might differ. This rounding > >>>> error has to be addressed. This patch prepares EAS code for better > >>>> precision in the coming EM improvements. > >>> > >>> Could you explain why 32bits results are not enough and you need to > >>> move to 64bits ? > >>> > >>> Right now the result is in the range [0..2^32[ mW. If you need more > >>> precision and you want to return uW instead, you will have a result in > >>> the range [0..4kW[ which seems to be still enough > >>> > >> > >> Currently we have the max value limit for 'power' in EM which is > >> EM_MAX_POWER 0xffff (64k - 1). We allow to register such big power > >> values ~64k mW (~64Watts) for an OPP. Then based on 'power' we > >> pre-calculate 'cost' fields: > >> cost[i] = power[i] * freq_max / freq[i] > >> So, for max freq the cost == power. Let's use that in the example. > >> > >> Then the em_cpu_energy() calculates as follow: > >> cost * sum_util / scale_cpu > >> We are interested in the first part - the value of multiplication. > > > > But all these are internal computations of the energy model. At the > > end, the computed energy that is returned by compute_energy() and > > em_cpu_energy(), fits in a long > > Let's take a look at existing *10000 precision for x CPUs: > cost * sum_util / scale_cpu = > (64k *10000) * (x * 800) / 1024 > which is: > x * ~500mln > > So to be close to overflowing u32 the 'x' has to be > (?=) 8 > (depends on sum_util). Sorry but I don't get your point. This patch is about the return type of compute_energy() and em_cpu_energy(). And even if we decide to return uW instead of mW, there is still a lot of margin. It's not because you need u64 for computing intermediate value that you must returns u64 > > > > >> > >> The sum_util values that we can see for x CPUs which have scale_cap=1024 > >> can be close to 800, let's use it in the example: > >> cost * sum_util = 64k * (x * 800), where > >> x=4: ~200mln > >> x=8: ~400mln > >> x=16: ~800mln > >> x=64: ~3200mln (last one which would fit in u32) > >> > >> When we increase the precision by even 100, then the above values won't > >> fit in the u32. Even a max cost of e.g. 10k mW and 100 precision has > >> issues: > >> cost * sum_util = (10k *100) * (x * 800), where > >> x=4: ~3200mln > >> x=8: ~6400mln > >> > >> For *1000 precision even a power of 1Watt becomes an issue: > >> cost * sum_util = (1k *1000) * (x * 800), where > >> x=4: ~3200mln > >> x=8: ~6400mln > >> > >> That's why to make the code safe for bigger power values, I had to use > >> the u64 on 32bit machines.