Received: by 2002:ac0:98c7:0:0:0:0:0 with SMTP id g7-v6csp608412imd; Fri, 26 Oct 2018 13:55:52 -0700 (PDT) X-Google-Smtp-Source: AJdET5fyuPyrH9LyEBPqFCokBoynVH/ct0ImwfgTiQxznLD8ybYiQ57spe7wDCEeYjY5/SUqnqtl X-Received: by 2002:a63:4f61:: with SMTP id p33-v6mr4921885pgl.71.1540587352313; Fri, 26 Oct 2018 13:55:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1540587352; cv=none; d=google.com; s=arc-20160816; b=m5Fl/VaCOQbx9VBYHVS0SI2mo/iYgrUkmuhnqDZ6F+qe3FzR7cwzpXFYmn/cS8fFYJ 2MciPI1VGh171LTB4DLYth9r5sisWxY3kz0oEXWzo82sTNQv4Pb5UvWynNHkjHfDnqLg Wm2jCD4mvC2efPs/SqVwuQsUJj8nV1jLx6+QCFoP/fPX12yBXthnCT4nrFA4VqQ33wJr dc2HdB5QSumrlbSS9eO/dvfzkIoZXB+k3PkQDgbh//C6ZP0yhbR7rdjWDics/6YWParV IqpPZNgbyh4BWG2hW+LRv191oLPUqdRrVFE9JioVuW9qG0xK6rwOoon5U1+rYVdPOGru ggHw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :message-id:in-reply-to:subject:cc:to:from:date; bh=8J8vAWdWqYBph4BB0fn6i8Vr4XOJK8S0LyqlEkMZ1hg=; b=fXxgEHbqSUIsw5h6CA5/E6SGv64RdrWTtf3VAGK/qxBSYUSjlbVf7/4brLE0e9J15Y xhHpPFTHJYyxJzkEF2VwZd1EXdbmg/1vFKyz1nNJkwoLM6XPMMSg9v9SHoCJZphUY0Dx 7eujE349N2n+UvkU0HbA7uZe6JPVp145PGjTXkDwfzNrCzQ9m2ZI2/JWuchqCVAV/9bA vDt81AV2lAgRNAFaRrPNYbUh/9D8CKuBGbQL825tLsSuDTAEf8Fy7tIg9Jj1qXExUO9F UxnHJQJqz+lzHd3ipctfaXmUxs2xAqCjr0NqbXcrYapqsrgtpoFFtCDh5FQM9xrv5JQj WM3w== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 3-v6si12104461ple.236.2018.10.26.13.55.36; Fri, 26 Oct 2018 13:55:52 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727787AbeJ0FdI (ORCPT + 99 others); Sat, 27 Oct 2018 01:33:08 -0400 Received: from mail2-relais-roc.national.inria.fr ([192.134.164.83]:62597 "EHLO mail2-relais-roc.national.inria.fr" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725947AbeJ0FdH (ORCPT ); Sat, 27 Oct 2018 01:33:07 -0400 X-IronPort-AV: E=Sophos;i="5.54,429,1534802400"; d="scan'208";a="353046059" Received: from 89-157-201-244.rev.numericable.fr (HELO hadrien) ([89.157.201.244]) by mail2-relais-roc.national.inria.fr with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 26 Oct 2018 22:54:34 +0200 Date: Fri, 26 Oct 2018 22:54:34 +0200 (CEST) From: Julia Lawall X-X-Sender: jll@hadrien To: Sasha Levin cc: Shayenne da Luz Moura , Greg Kroah-Hartman , Hans de Goede , Michael Thayer , devel@driverdev.osuosl.org, linux-kernel@vger.kernel.org, outreachy-kernel@googlegroups.com, joe@perches.com Subject: Re: [Outreachy kernel] [RESEND PATCH 2/2] staging: vboxvideo: Use unsigned int instead bool In-Reply-To: <20181026204225.GH2015@sasha-vm> Message-ID: References: <211701e4ae42acd95afb24713314bce5a4c58ecf.1540580493.git.shayenneluzmoura@gmail.com> <20181026204225.GH2015@sasha-vm> User-Agent: Alpine 2.21 (DEB 202 2017-01-01) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org [Adding Joe Perches] On Fri, 26 Oct 2018, Sasha Levin wrote: > On Fri, Oct 26, 2018 at 04:04:45PM -0300, Shayenne da Luz Moura wrote: > > This change was suggested by checkpath.pl. Use unsigned int with bitfield > > allocate only one bit to the boolean variable. > > > > CHECK: Avoid using bool structure members because of possible alignment > > issues > > > > Signed-off-by: Shayenne da Luz Moura > > --- > > drivers/staging/vboxvideo/vbox_drv.h | 14 +++++++------- > > drivers/staging/vboxvideo/vboxvideo_guest.h | 2 +- > > 2 files changed, 8 insertions(+), 8 deletions(-) > > > > diff --git a/drivers/staging/vboxvideo/vbox_drv.h > > b/drivers/staging/vboxvideo/vbox_drv.h > > index 594f84272957..7d3e329a6b1c 100644 > > --- a/drivers/staging/vboxvideo/vbox_drv.h > > +++ b/drivers/staging/vboxvideo/vbox_drv.h > > @@ -81,7 +81,7 @@ struct vbox_private { > > u8 __iomem *vbva_buffers; > > struct gen_pool *guest_pool; > > struct vbva_buf_ctx *vbva_info; > > - bool any_pitch; > > + unsigned int any_pitch:1; > > u32 num_crtcs; > > /** Amount of available VRAM, including space used for buffers. */ > > u32 full_vram_size; > > Using bitfields for booleans in these cases is less efficient than just > using "regular" booleans for two reasons: > > 1. It will use the same amount of space. Due to alignment requirements, > the compiler can't squeeze in anything into the 7 bits that are now > "free". Each member, unless it's another bitfield, must start at a whole > byte. > > 2. This is actually less efficient (slower) for the compiler to work > with. The smallest granularity we have to access memory is 1 byte; we > can't set individual bits directly in memory. For the original code, the > assembly for 'vbox_private.any_pitch = true' would look something like > this: > > movl $0x1,-0x10(%rsp) > > As you can see, the compiler can directly write into the variable. > However, when we switch to using bitfields, the compiler must preserve > the original value of the other 7 bits, so it must first read them from > memory, manipulate the value and write it back. The assembly would > look something like this: > > movzbl -0x10(%rsp),%eax > or $0x1,%eax > mov %al,-0x10(%rsp) > > Which is less efficient than what was previously happening. Maybe checkpatch could be more precise about what kind of bools should be changed? julia