Received: by 2002:ac0:98c7:0:0:0:0:0 with SMTP id g7-v6csp598904imd; Fri, 26 Oct 2018 13:44:46 -0700 (PDT) X-Google-Smtp-Source: AJdET5fteJKEC308Q6IMODLv35fCVvEreANIZtva89I0G8RfDWxk09XH50z4lSBq2ckYsq4SALim X-Received: by 2002:a63:5c61:: with SMTP id n33-v6mr4735021pgm.1.1540586686219; Fri, 26 Oct 2018 13:44:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1540586686; cv=none; d=google.com; s=arc-20160816; b=MRDzrOTI60ChE6U4yhsw3pggPaC39+ljqwAU6hpjL0BjcQtqtlYXGZ51TfS7dKK7ve 3ukaExFkbSPGJGKRM9GrIGH2XUeNeSO0kLjYL3fmZa+GiOTBNrAkN4n2EoD/jrwwHG3A f6v0eqlotmmJJj0ujlrFWOIRBU3Zj4KRGjNkGfNg+8wM7aAZ2/Y0o6WcxwGjZY50bLYX gEjVAeLd4pXnmCKOF/qG/rmrV5f5HYj3yt9yDSUzh/w6Rtawg+rHkDSJY0/1rAmcobEk ldoJPbzN7hoZGLyc8q7d69AQCI4PhYCFpMlY5foCfsYwVsK6qOn1Lsldeppt0Yttl4A1 9P3g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=yYn/weYHlFV31GeMW1wvhRKFTYvmrVOjjCXjNWJuqJc=; b=Ylvf93Kx/Y8zEnBWbxQD+rp96uRkgAsvMhj7Tj+8+ESnAV7cIrVO3CBOakhLZCw6G4 Wl8sutBlNe+CqKoAVfoA0rN3NnPc6tdQRNvNi/g3qmXZ9cOU0OcJbpSMXMBlUaePXp5h ctqVLO9IGNpawJd8y9QLIGO/01o2G9Hk/vl2/apiJ35LBifMEKjksx3oWRnbfwnuh73E 1CPtwPtQlABActSIeeHL9Ootw/i9KA7kNG+cI+bbp3G6q8yTe7RqBLWEAqFmK63dd2gD WsQygZRIWP2eX0quvjtsJDPtbcsSjaLSpngYlTUnuDQ5yiiwQ1CVLnHK9P70PyteR0o9 8tvQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=hhE9nvAq; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id a21-v6si11800064pff.126.2018.10.26.13.44.30; Fri, 26 Oct 2018 13:44:46 -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; dkim=pass header.i=@kernel.org header.s=default header.b=hhE9nvAq; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727461AbeJ0FU5 (ORCPT + 99 others); Sat, 27 Oct 2018 01:20:57 -0400 Received: from mail.kernel.org ([198.145.29.99]:38494 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725808AbeJ0FU5 (ORCPT ); Sat, 27 Oct 2018 01:20:57 -0400 Received: from localhost (unknown [167.98.65.38]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 47D1C20856; Fri, 26 Oct 2018 20:42:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1540586547; bh=y6GHLD3iTfoUWTyAENeES4MoLFw0vJUADnQ3lSdtbhk=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=hhE9nvAq/8DD2EwHleLGhktokBMxiQspgqXH8QJtPNQ0JDIYI27gisXZK81Jvo52G fj7sCIkZ2YRYWLnVYD6CSnJHxT3hVSObtJjWgy1UXNfKCq0pXHJpbCqere9dyG3wPO MFQBn8QnRkv/WK3SlajbUhB2uT40b1g5IcQtzmW8= Date: Fri, 26 Oct 2018 16:42:25 -0400 From: Sasha Levin To: Shayenne da Luz Moura Cc: Greg Kroah-Hartman , Hans de Goede , Michael Thayer , devel@driverdev.osuosl.org, linux-kernel@vger.kernel.org, outreachy-kernel@googlegroups.com Subject: Re: [Outreachy kernel] [RESEND PATCH 2/2] staging: vboxvideo: Use unsigned int instead bool Message-ID: <20181026204225.GH2015@sasha-vm> References: <211701e4ae42acd95afb24713314bce5a4c58ecf.1540580493.git.shayenneluzmoura@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii; format=flowed Content-Disposition: inline In-Reply-To: <211701e4ae42acd95afb24713314bce5a4c58ecf.1540580493.git.shayenneluzmoura@gmail.com> User-Agent: Mutt/1.9.4 (2018-02-28) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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. -- Thanks, Sasha