Received: by 2002:a05:7412:8521:b0:e2:908c:2ebd with SMTP id t33csp2033529rdf; Mon, 6 Nov 2023 02:47:14 -0800 (PST) X-Google-Smtp-Source: AGHT+IFyxOhpS1lsGAiiui+iAKFCT12gMJ0QHdpIDjNSg7XWYbyerqv8EGAvghtjXgF2ga7UW0Qj X-Received: by 2002:a17:90a:c001:b0:280:a464:e9d4 with SMTP id p1-20020a17090ac00100b00280a464e9d4mr14639449pjt.8.1699267633889; Mon, 06 Nov 2023 02:47:13 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1699267633; cv=none; d=google.com; s=arc-20160816; b=X4pglmThV8e0gAd5srVJ4YInSv6/cuOHw5gJTWJsIc/SQwweiC1A/ADnfbHECxSN2/ d4bYGuW9IGlu6j6X7l1GVHmLmlGWEjitqRHV7racuGn4uX52LKFDcld1YZhV31B4ZUMR UMpUOSDDguDv0E8WEeAkooeKILBwGOQVlWsEmWGif4Gy1ylFbkhKxiXaSFmqG/a9hsKo Q/RpS8zZoFFNkem5dNaiu6TPOqp43Otx9y/1h3H7jnZccSQYHHECfJIwXHTH3ncpgbgO Jgn3w6ZQ6zMJK1WBEMVtkhAufnR4y/laEYlgYDtKeqkZLiryWPA5EVoqDvMF583P7Hq/ SF4Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to :content-language:references:cc:to:from:subject:user-agent :mime-version:date:message-id:dkim-signature; bh=UBBHGlGug2sDaMRAASVGz4oXj62d4vp0Qb3y5VCW+Oc=; fh=RmpTCIqi0Sb1cB6COH+VAJony6G9zB64KMZOJaWEjT4=; b=FRc/PUhNbaTZM4IVWWyATU4cd7ABx9GOhcO2+M3SaQZaQQbPU3kO0PGJTEwHCF0+6G lU5pn3TELkunZTjYndbZR2z2pd9MqcrpE8T5b0SA/vT3U5zerA1CHd5lxONBFD2lTX26 rWBKmsf3Ktnc/opqRXy+sF8OZxE8IEp+d0LsijwAWqCCBXSbtAm1jgaYrfyLoqh0jGuH KzdJ5G3P8JSfUUnbafR88bxJYbjxYWp6ZhHM3HM9qgzfOEANalNJZDRa2bWjKTIyy7/Y 46YG7THoqpBuRBit/yoyq57CTMlzliwoHhHserlzyiTPoF6KWNkh4JFjWo5/wG/hjpEL SC4Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=JEc9CMsu; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:5 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from groat.vger.email (groat.vger.email. [2620:137:e000::3:5]) by mx.google.com with ESMTPS id ip2-20020a17090b314200b00280072b397csi8882444pjb.30.2023.11.06.02.47.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 06 Nov 2023 02:47:13 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:5 as permitted sender) client-ip=2620:137:e000::3:5; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=JEc9CMsu; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:5 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by groat.vger.email (Postfix) with ESMTP id D7D0F80A364D; Mon, 6 Nov 2023 02:47:10 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at groat.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231186AbjKFKq6 (ORCPT + 99 others); Mon, 6 Nov 2023 05:46:58 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57230 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230021AbjKFKq5 (ORCPT ); Mon, 6 Nov 2023 05:46:57 -0500 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1FF3DA4 for ; Mon, 6 Nov 2023 02:46:14 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1699267573; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=UBBHGlGug2sDaMRAASVGz4oXj62d4vp0Qb3y5VCW+Oc=; b=JEc9CMsu7FO+jO6sLV1NHKm/jeyD4R6uvFgVt1c8Pq6Gos1TmzTI8X7xbMkcIC3l12SNw4 LURjjCS6vw4bGlAVX1Io3HUqzylHTlkKXLoYUtMkeF/E2XIhjhsBQJNz3zXHx44xElkOj4 XwypiwCIbKhMMG17YTNwe7nyjNPrIPc= Received: from mail-wr1-f72.google.com (mail-wr1-f72.google.com [209.85.221.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-500-h8cSF4KdOkiTBYXSf3a6UA-1; Mon, 06 Nov 2023 05:46:12 -0500 X-MC-Unique: h8cSF4KdOkiTBYXSf3a6UA-1 Received: by mail-wr1-f72.google.com with SMTP id ffacd0b85a97d-32da8de4833so2228427f8f.3 for ; Mon, 06 Nov 2023 02:46:11 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1699267570; x=1699872370; h=content-transfer-encoding:in-reply-to:content-language:references :cc:to:from:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=UBBHGlGug2sDaMRAASVGz4oXj62d4vp0Qb3y5VCW+Oc=; b=s1W1YwvtkcuWiUbtFXIzTSY3iteTe5nwF4aKdXlwWsGLymD3K/u9PCCWObFZHpW48a Cukz4Zi1dKmtxE1934d2reEZqrIoaFzcDOK53YsFJh7tlNDU41lAUvsZfoLJJHzLEgO9 RZtVx6+p91CW46o5imemdHKYKtSWSyUEYsmCD+MZcaTDfm8+bSqR8Q34draRa8tld5dc hWqq6zvp42kU3viYm5rJR3HxnKjAZu8zk6ByYUplUxuI+wjRouXfkD66+9Q3ZfR+87FW LPAT9kDd533jMeTCX3D6ixQMy4FVkDhBSiEAyEimDBJfftAEw/JoPX3m0rtFwuJK+oHy FETw== X-Gm-Message-State: AOJu0YycEAykrv9v94W6fBoXlPZ5lVZbxyV60LLP+avgPp4Xg3sUWbvY pT1nLgnh0f7YZxXxoj4Nj+3d99lK8T+5vOkrwWho9al6MJD3J2vm7koQgNVmpaoyMzmbVIGl4TI h8fOGJsEiIwNEL10Oejss04Nc0aGuSDAg X-Received: by 2002:a5d:6d87:0:b0:32f:908e:c7e0 with SMTP id l7-20020a5d6d87000000b0032f908ec7e0mr17559316wrs.28.1699267570468; Mon, 06 Nov 2023 02:46:10 -0800 (PST) X-Received: by 2002:a5d:6d87:0:b0:32f:908e:c7e0 with SMTP id l7-20020a5d6d87000000b0032f908ec7e0mr17559295wrs.28.1699267570128; Mon, 06 Nov 2023 02:46:10 -0800 (PST) Received: from ?IPV6:2a01:e0a:c:37e0:ced3:55bd:f454:e722? ([2a01:e0a:c:37e0:ced3:55bd:f454:e722]) by smtp.gmail.com with ESMTPSA id o17-20020adfcf11000000b0032da319a27asm9148638wrj.9.2023.11.06.02.46.09 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 06 Nov 2023 02:46:09 -0800 (PST) Message-ID: Date: Mon, 6 Nov 2023 11:46:08 +0100 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH] drm/mgag200: Flush the cache to improve latency From: Jocelyn Falempe To: Thomas Zimmermann , dri-devel@lists.freedesktop.org, airlied@redhat.com, daniel@ffwll.ch Cc: Linux Kernel Mailing List References: <20231019135655.313759-1-jfalempe@redhat.com> <660c0260-0e22-4e9c-ab13-157adaa0b14d@suse.de> <74b367bd-ac80-478b-8f82-e98cb6e40475@redhat.com> Content-Language: en-US In-Reply-To: <74b367bd-ac80-478b-8f82-e98cb6e40475@redhat.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-0.9 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on groat.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (groat.vger.email [0.0.0.0]); Mon, 06 Nov 2023 02:47:11 -0800 (PST) On 23/10/2023 10:30, Jocelyn Falempe wrote: > On 20/10/2023 14:06, Thomas Zimmermann wrote: >> (cc'ing lkml for feedback) >> >> Hi Jocelyn >> >> Am 19.10.23 um 15:55 schrieb Jocelyn Falempe: >>> We found a regression in v5.10 on real-time server, using the >>> rt-kernel and the mgag200 driver. It's some really specialized >>> workload, with <10us latency expectation on isolated core. >>> After the v5.10, the real time tasks missed their <10us latency >>> when something prints on the screen (fbcon or printk) >> >> I'd like to hear the opinion of the RT-devs on this patch. Because >> AFAIK we never did such a workaround in other drivers. And AFAIK >> printk is a PITA anyway. > > Most other drivers uses DMA, which means this workaround can't apply to > them. > >> >> IMHO if that RT system cannot handle differences in framebuffer >> caching, it's under-powered. It's just a matter of time until >> something else changes and the problem returns. And (honest question) >> as it's an x86-64, how do they handle System Management Mode? > > I think it's not a big news, that the Matrox G200 from 1999 is > under-powered. > I was also a bit surprised that flushing the cache would have such > effect on latency. The tests we are doing can run 24h with the > workaround, without any interrupt taking more than 10us. Without the > workaround, every ~30s the interrupt failed its 10us target. > >> >>> >>> The regression has been bisected to 2 commits: >>> 0b34d58b6c32 ("drm/mgag200: Enable caching for SHMEM pages") >>> 4862ffaec523 ("drm/mgag200: Move vmap out of commit tail") >>> >>> The first one changed the system memory framebuffer from Write-Combine >>> to the default caching. >>> Before the second commit, the mgag200 driver used to unmap the >>> framebuffer after each frame, which implicitly does a cache flush. >>> Both regressions are fixed by the following patch, which forces a >>> cache flush after each frame, reverting to almost v5.9 behavior. >> >> With that second commit, we essentially never unmap an active >> framebuffer console. But with commit >> >> 359c6649cd9a ("drm/gem: Implement shadow-plane {begin, end}_fb_access >> with vmap") >> >> we now again unmap the console framebuffer after the pageflip happened. >> >> So how does the latest kernel behave wrt to the problem? > > The regression was found when upgrading the server from v5.4 to v5.14, > so we didn't test with later kernels. > We will test with v6.3 (which should have 359c6649cd9a ) and see what it > gives. I don't have a clear explanation, but testing with v6.3, and forcing the Write Combine, doesn't fix the latency issue. So forcing the cache flush is still needed. Also, on some systems, they use "isolated cpu" to handle RT task, but with a standard kernel (so without the CONFIG_PREEMPT_RT). So I'm wondering if we can use a kernel module parameter for this, so that users that wants to achieve low latency, can opt-in ? something like mgag200.force_cache_flush=1 or mgag200.low_latency=1 ? Best regards, -- Jocelyn >> >>> This is necessary only if you have strong realtime constraints, so I >>> put the cache flush under the CONFIG_PREEMPT_RT config flag. >>> Also clflush is only availabe on x86, (and this issue has only been >>> reproduced on x86_64) so it's also under the CONFIG_X86 config flag. >>> >>> Fixes: 0b34d58b6c32 ("drm/mgag200: Enable caching for SHMEM pages") >>> Fixes: 4862ffaec523 ("drm/mgag200: Move vmap out of commit tail") >>> Signed-off-by: Jocelyn Falempe >>> --- >>>   drivers/gpu/drm/mgag200/mgag200_mode.c | 5 +++++ >>>   1 file changed, 5 insertions(+) >>> >>> diff --git a/drivers/gpu/drm/mgag200/mgag200_mode.c >>> b/drivers/gpu/drm/mgag200/mgag200_mode.c >>> index af3ce5a6a636..11660cd29cea 100644 >>> --- a/drivers/gpu/drm/mgag200/mgag200_mode.c >>> +++ b/drivers/gpu/drm/mgag200/mgag200_mode.c >>> @@ -13,6 +13,7 @@ >>>   #include >>>   #include >>> +#include >>>   #include >>>   #include >>>   #include >>> @@ -436,6 +437,10 @@ static void mgag200_handle_damage(struct >>> mga_device *mdev, const struct iosys_ma >>>       iosys_map_incr(&dst, drm_fb_clip_offset(fb->pitches[0], >>> fb->format, clip)); >>>       drm_fb_memcpy(&dst, fb->pitches, vmap, fb, clip); >>> +    /* On RT systems, flushing the cache reduces the latency for >>> other RT tasks */ >>> +#if defined(CONFIG_X86) && defined(CONFIG_PREEMPT_RT) >>> +    drm_clflush_virt_range(vmap, fb->height * fb->pitches[0]); >>> +#endif >> >> Your second commit is part of a larger patchset that updates several >> drivers. They might all be affected. So if anything, the patch should >> go here before the unmap call: >> >> https://elixir.bootlin.com/linux/v6.5/source/drivers/gpu/drm/drm_gem_atomic_helper.c#L377 >> > The regression was found only with G200 currently, so I don't want to > apply it blindly on other drivers. > > Thanks for your help, > > Best regards, >