From: Christophe Fergeau Subject: Re: [Spice-devel] [drm/qxl 5/6] qxl: Don't notify userspace when monitors config is unchanged Date: Wed, 2 Nov 2016 17:31:28 +0100 Message-ID: <20161102163128.oikesemvavdhhcoo@edamame.cdg.redhat.com> References: <20161028121227.16904-1-cfergeau@redhat.com> <20161028121227.16904-6-cfergeau@redhat.com> <2100365690.7702214.1477915209986.JavaMail.zimbra@redhat.com> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="===============0727674979==" Return-path: In-Reply-To: <2100365690.7702214.1477915209986.JavaMail.zimbra@redhat.com> List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" To: Frediano Ziglio Cc: spice-devel@lists.freedesktop.org, dri-devel@lists.freedesktop.org, airlied@redhat.com List-Id: dri-devel@lists.freedesktop.org --===============0727674979== Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="2nru6osvay4d5enm" Content-Disposition: inline --2nru6osvay4d5enm Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable Hey, On Mon, Oct 31, 2016 at 08:00:09AM -0400, Frediano Ziglio wrote: > > diff --git a/drivers/gpu/drm/qxl/qxl_display.c > > b/drivers/gpu/drm/qxl/qxl_display.c > > index 156b7de..edb90f6 100644 > > --- a/drivers/gpu/drm/qxl/qxl_display.c > > +++ b/drivers/gpu/drm/qxl/qxl_display.c > > @@ -57,11 +57,18 @@ static void qxl_alloc_client_monitors_config(struct > > qxl_device *qdev, unsigned c > > qdev->client_monitors_config->count =3D count; > > } > > =20 > > +enum MonitorsConfigCopyStatus { > > + MONITORS_CONFIG_COPIED, > > + MONITORS_CONFIG_UNCHANGED, > > + MONITORS_CONFIG_BAD_CRC, > > +}; > > + >=20 > I don't remember exactly kernel style, a=20 >=20 > typedef enum { > MONITORS_CONFIG_COPIED, > MONITORS_CONFIG_UNCHANGED, > MONITORS_CONFIG_BAD_CRC, > } MonitorsConfigCopyStatus; >=20 > could make following code shorter. A git grep enum in qxl/ returns a dozen results, none of these using typedef, I guess I just followed that style. >=20 > > static int qxl_display_copy_rom_client_monitors_config(struct qxl_devi= ce > > *qdev) >=20 > why not returning MonitorsConfigCopyStatus ? No idea ;) I'll change the patch. >=20 > > { > > int i; > > int num_monitors; > > uint32_t crc; > > + bool changed =3D false; > > =20 >=20 > using a "MonitorsConfigCopyStatus res =3D MONITORS_CONFIG_UNCHANGED" here > could make return statement shorter. >=20 > > num_monitors =3D qdev->rom->client_monitors_config.count; > > crc =3D crc32(0, (const uint8_t *)&qdev->rom->client_monitors_config, > > @@ -88,17 +99,42 @@ static int > > qxl_display_copy_rom_client_monitors_config(struct qxl_device *qdev) > > &qdev->rom->client_monitors_config.heads[i]; > > struct qxl_head *client_head =3D > > &qdev->client_monitors_config->heads[i]; > > - client_head->x =3D c_rect->left; > > - client_head->y =3D c_rect->top; > > - client_head->width =3D c_rect->right - c_rect->left; > > - client_head->height =3D c_rect->bottom - c_rect->top; > > - client_head->surface_id =3D 0; > > - client_head->id =3D i; > > - client_head->flags =3D 0; > > + if (client_head->x !=3D c_rect->left) { > > + client_head->x =3D c_rect->left; > > + changed =3D true; > > + } > > + if (client_head->y !=3D c_rect->top) { > > + client_head->y =3D c_rect->top; > > + changed =3D true; > > + } > > + if (client_head->width !=3D c_rect->right - c_rect->left) { > > + client_head->width =3D c_rect->right - c_rect->left; > > + changed =3D true; > > + } > > + if (client_head->height !=3D c_rect->bottom - c_rect->top) { > > + client_head->height =3D c_rect->bottom - c_rect->top; > > + changed =3D true; > > + } > > + if (client_head->surface_id !=3D 0) { > > + client_head->surface_id =3D 0; > > + changed =3D true; > > + } > > + if (client_head->id !=3D i) { > > + client_head->id =3D i; > > + changed =3D true; > > + } >=20 > quite similar code... I would write a macro but I'm a too macro fun :) > Would be something like this >=20 > if (client_head->id !=3D i) > res =3D MONITORS_CONFIG_COPIED; > client_head->id =3D i; >=20 > make sense? I'm not a big macro fan, especially if they have side effects, so I preferred to keep things explicit, even though I am annoyed by the repetitive code too /o\ >=20 > > + if (client_head->flags !=3D 0) { > > + client_head->flags =3D 0; > > + changed =3D true; > > + } >=20 > why testing flags change if is always 0 ? Yeah, same for surface_id above actually. Just mechanically changed everything ;) >=20 > Usually I would write something like >=20 > for (;;) { > status =3D qxl_display_copy_rom_client_monitors_config(qdev); > if (status !=3D MONITORS_CONFIG_BAD_CRC) > break; > qxl_io_log(qdev, "failed crc check for client_monitors_config," > " retrying\n"); > } >=20 > or >=20 > while ((status =3D qxl_display_copy_rom_client_monitors_config(qdev)) > =3D=3D MONITORS_CONFIG_BAD_CRC) { > qxl_io_log(qdev, "failed crc check for client_monitors_config," > " retrying\n"); > } >=20 > (just style and probably indentation is even wrong) Same as above, I don't like either, first one obscures the loop exit condition, and second one makes the assignment/test harder to read. Christophe --2nru6osvay4d5enm Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQIcBAEBCAAGBQJYGhTgAAoJEKnYwhQprGyCgKIP/1KfW+v+M45XYzHL5n0zZFQo UF5LHTiI71WrVfVFEpiYGxchH4V9uEuMoSnI5EvsnToyqP+leScSuCidEHo8y+xQ dbq6jCnD7Sq95hVF7oKJlv3+LGZe5nWLYx3L2oR4kMikhRjeEhdqxDE3xJmMWL2P uQJyd0PF7VTOs6JfAhyB3hMrqK+1/raJkm+4JiIJjlBUGNfuGr28rJWB1+3aMXmR N/9mpH9mAB13TEXG+JCyJ70SjHRLgOjQYKk6W1z4Kwch3BcUxUP/bMAk6ksSiEAu 8VW2t8jaJD00JtshtgnCoYBKMK4YSlQRTTGNJkyamdWD1ysIBxIgYWvlTZJJ91jY pJPBoaKqYmzmYBfXGYRev/gH0Tmm02n+SfCKsurkQ8VkaQftIF7Zc6aajZMrkGiH 70VJ5gFlPGtQyltWt7Ovgbp7IUHlpGEqSXJwaHvaCF8aBR7Ir+k3u68+L9i+N3IJ SRgtg0Q6ViHhZMKYoMW5hTJN3U8J3sxbbv3+f3e1pdcQJ75hC6BpO9yDVBlGdip8 n9fgyLuhv8HxiA5FF/ZhVU/IXBWUeh8rLu+US3/XFwZiYNiNHwpZid7VuqIZxTVU yv2wQL8hTlWU3OVhgdSHhWvZyq1REToRKrfPE6qFUdiFSMgeHQZLVe20kUjW5hPh K5dTxQWbWqcznqmDz5Ta =x/oy -----END PGP SIGNATURE----- --2nru6osvay4d5enm-- --===============0727674979== Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: base64 Content-Disposition: inline X19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX18KZHJpLWRldmVs IG1haWxpbmcgbGlzdApkcmktZGV2ZWxAbGlzdHMuZnJlZWRlc2t0b3Aub3JnCmh0dHBzOi8vbGlz dHMuZnJlZWRlc2t0b3Aub3JnL21haWxtYW4vbGlzdGluZm8vZHJpLWRldmVsCg== --===============0727674979==--