Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp10259867rwb; Fri, 25 Nov 2022 02:57:22 -0800 (PST) X-Google-Smtp-Source: AA0mqf5czP/IEi9Fv9h/tS7bc8cOgV+vbH6l31rh2cSS6ZTo3leVdcnZXqtd5Ov8WHJzf2txgvFI X-Received: by 2002:a05:6402:1d90:b0:46a:8e73:2b93 with SMTP id dk16-20020a0564021d9000b0046a8e732b93mr6010711edb.404.1669373842197; Fri, 25 Nov 2022 02:57:22 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669373842; cv=none; d=google.com; s=arc-20160816; b=aXfTfjQWGfEE7NT82oRddEqcjj8BrSJoH1IDWygEZXbWAC2RTYdkzxJfJp+5TVFFh6 gzl9j6Q/vrSzBJWGYCZjBZpNkqOFKPDpdhV7kF9FvLvFihWqOYIpxZXoTVWmMwD/qu/V dWUnoA719IDvsGVEcE+3NtlKZp50KDt1CPAB2w5XZeaQXLTCWc/yHJ3AJcKUZGQudiGa tZA7a1EuOkZ34n0tOwoAF+KrouL9hfFC5953uFF2oJdWVblUjIIpwhkYFERs8UQxb8+k 5F/H8uQVL3CvPNMyoSPmdnJcr1Fbg6D9h4oqt+xXs1vQyonDCDnN7GXpQ9IbROrP3nTm U/Uw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:message-id:date:references :in-reply-to:subject:cc:to:dkim-signature:dkim-signature:from; bh=nwozR5nRSQcQOic3zPLWI/Ew+VMp0/ualSICVMwXUeg=; b=KkAJzXNdqDpY9+v/7Vrv2E9rDBSZYGJhnUca53WLRghnGN+yqG8hCxEW2HEgJpXRZO Hz0nAw6uMz4boolavvmXLnLowRviUPcjsvn0xSBoTn+jKm8V4MCO/vZkCzHBpiU8iJG9 3C0NHjT8v9P0bidWIXdoD42sOamBVdq6gl051fC4N8MDfVAalGsSXImvpi9oF+OI65WA F4Hk/fGXuUfcGnpMPCbgkteWX5IjAXyhAu1Fqh8bTKZYC4/P6dT+kleUNdfBIEChj3Tj 9g2WOfY8BGHfElpusLoSGEFI2FYt5Ji7oJe26hCvA0rF9StLlzW4dVnTWwk/S9rYUjap n4cw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=G+XsqUl9; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id y14-20020a50bb0e000000b0046a7ad0bb17si2940299ede.586.2022.11.25.02.56.57; Fri, 25 Nov 2022 02:57:22 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=G+XsqUl9; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230241AbiKYKto (ORCPT + 87 others); Fri, 25 Nov 2022 05:49:44 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45052 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230243AbiKYKtn (ORCPT ); Fri, 25 Nov 2022 05:49:43 -0500 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 08A6748424 for ; Fri, 25 Nov 2022 02:49:40 -0800 (PST) From: John Ogness DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1669373379; 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: in-reply-to:in-reply-to:references:references; bh=nwozR5nRSQcQOic3zPLWI/Ew+VMp0/ualSICVMwXUeg=; b=G+XsqUl9cz3x33oC4IKE1n8JkrPMykb6qYMDWPGS5kyWcgTS4QWGuLtDBrbBJMC6OqmAQ5 S3GqoTR+a0wp6PLIiuoAz5zVBwoWvYzW4Z5BK0dl/qKdDWHJSAzz6rf4XO2Bhm+IkvJI8I uETrOqALcntF1mXV3Kp/LX6GTeTQmnllmI+EH49XgZQjwniAzE/YdSXwSwqmscmWn0ggyU ZC7m4+xaEiRqZY0pzOTVRFs5SQJXkJqUjBoeCh/QmmGoP5nEtyCPO2wjzAnkWAgfsxpwZQ Do6dH+1bug9togP2d8u1P/gpdoLDCe3Jqjl7p+goOISxL+HchNSSuN/AUMoHWQ== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1669373379; 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: in-reply-to:in-reply-to:references:references; bh=nwozR5nRSQcQOic3zPLWI/Ew+VMp0/ualSICVMwXUeg=; b=o2P2+51tJsmM4W4cZU5SsHj90rIMoZ8M3ruPFWQ4XPqFLe6T+yxshfrgo3NdWBGU8cmU0S UFnSmj8tW+UbSZAQ== To: Petr Mladek Cc: Sergey Senozhatsky , Steven Rostedt , Thomas Gleixner , linux-kernel@vger.kernel.org, Greg Kroah-Hartman Subject: Re: [PATCH printk v2 6/7] printk: Use an output buffer descriptor struct for emit In-Reply-To: References: <20221123231400.614679-1-john.ogness@linutronix.de> <20221123231400.614679-7-john.ogness@linutronix.de> <87o7swkqar.fsf@jogness.linutronix.de> Date: Fri, 25 Nov 2022 11:55:28 +0106 Message-ID: <87sfi7s407.fsf@jogness.linutronix.de> MIME-Version: 1.0 Content-Type: text/plain X-Spam-Status: No, score=-3.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,INVALID_DATE_TZ_ABSURD, RCVD_IN_DNSWL_MED,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 2022-11-25, Petr Mladek wrote: > I am not sure if we are talking about the same thing. My idea was to > do: We are and your idea is fine. >> The "problem" with this idea is that record_print_text() creates the >> normal output in-place within the readbuf. So for normal messages with >> no dropped messages, we still end up writing out the readbuf. > > We handle this this in console_get_next_message() by reading the > messages into the right buffer: > > struct console_buffers { > char outbuf[CONSOLE_EXT_LOG_MAX]; > char readbuf[CONSOLE_LOG_MAX]; > }; > > boot is_extcon = console_srcu_read_flags(con) & CON_EXTENDED; > > /* > * Normal consoles might read the message into the outbuf directly. > * Console headers are added inplace. > */ > if (is_extcon) > prb_rec_init_rd(&r, &info, &cbufs->readbuf[0], sizeof(cbufs->readbuf)); > else > prb_rec_init_rd(&r, &info, &cbufs->outbuf[0], sizeof(cbufs->outbuf)); > > if (!prb_read_valid(prb, con->seq, &r)) > return false; We do not know if there will be dropped messages until _after_ we call prb_read_valid(). > if (is_extcon) { > len = info_print_ext_header(cbufs->outbuf, sizeof(cbufs->outbuf, r.info); > len += msg_print_ext_body(cbufs->outbuf + len, sizeof(cbufs->outbuf) - len, > &r.text_buf[0], r.info->text_len, &r.info->dev_info); > } else { > len = record_print_text(&r, console_msg_format & MSG_FORMAT_SYSLOG, printk_time); > } And the dropped messages should be inserted now somewhere too. The fact is that we need two different sized buffers. Which one is used for output is not known in advance. I think it is misleading to name the variables based on their purpose because their purpose changes depending on the situation. I think the only usefulness we can derive from the names is their size. How about naming them: @buffer_console_log_max @buffer_console_ext_log_max >> Since we sometimes output the in-place readbuf and sometimes a newly >> written buffer, it is nice that console_message can abstract that >> out. >> >> Also, right now @is_extmsg is the only input variable. For >> thread/atomic consoles, the input variables @seq and @dropped will be >> added. console_message will then have its own copy of all the >> information needed to let itself get filled and >> console_get_next_message() will no longer require the console as an >> argument. >> >> This is important for the thread/atomic consoles because it removes >> all locking constraints from console_get_next_message(). For _this_ >> series, console_get_next_message() still requires holding the >> console_lock because it is accessing con->seq and con->dropped. >> >> I could have added @seq and @dropped to console_message for this >> series, but for the legacy consoles it looks like a lot of >> unnecessary copying. Only with the thread/atomic consoles does the >> benefit become obvious. > > I could imagine adding these metadata into the struct console_buffers. > Or we could call it struct console_messages from the beginning. > > We could even completely move con->seq, con->dropped into this new > structure. It would safe even more copies. Well, consoles still need to have their own copy of @seq and @dropped for proper per-console tracking. But the buffers are globally shared. For this series I will drop @is_extmsg from struct console_message and instead make it an argument of console_get_next_message() and msg_print_dropped(). That makes more sense at this point. (It needs to be a variable because it is not safe to re-read flags multiple times when constructing the message.) For v3 I will move the two buffers (with whatever name we decide is best) into struct console_message and remove the struct console_buffers definition. That will also remove the use of @cbufs everywhere. For devkmsg I can replace @cbufs with separate @readbuf and @outbuf buffers since that is always their correct purpose for devkmsg. John