From patchwork Wed Apr 24 17:08:40 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Stultz X-Patchwork-Id: 162803 Delivered-To: patches@linaro.org Received: by 2002:a02:c6d8:0:0:0:0:0 with SMTP id r24csp904032jan; Wed, 24 Apr 2019 10:08:54 -0700 (PDT) X-Received: by 2002:a62:2a97:: with SMTP id q145mr35392776pfq.22.1556125734224; Wed, 24 Apr 2019 10:08:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1556125734; cv=none; d=google.com; s=arc-20160816; b=0bksPkEd0/Xbe/MdG6oGCuPRlc425IgHmSArRzOqcJUTMEyQH1Dr2NmVFFDYkjmUM5 QEHFXyDeI4BmOFnNGrlZi6YRhoAC8TKD56V3FNIjL2uJn1dpWt8/IlpM1NBuew1o65W4 bGQ9h5mOt+1qB2YLmvbW+xDorndsRK/VMRcPErUzSrzkbyg9lZEg8CR6dvpMtJy5aBeE j0hQso38mJWE0V+2mRd9TZ42+c3S77eU0J91J49oboxdV3YuC/5hNfvT8sJf5ZLWvFbt 9+mBrO5vbvRI3Xli0/m683wPdI+fadgBQbKfvWLIJw4D04Q3uxtiumiNV6ro+PKljSa8 Y43A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=Kw97zKx6ijTQMTY8hmHHesW3NQxmgImJerDwv67tN38=; b=DxBrF30VCp6UOAgJGhlrEny/ZhkYpyodWgNxy4QSJKunY+5OxwuR+VocgxtPN6ROew EFtEa5WqJYi2j6k70H9oSDCktfb/n+/8r7y9CDmEhc0x0wM2DDdjx/12OXlAz04z6I9q vC1cdm7SdvaatXmyqOKok8nV1+PW4mM//H1OBe4XdOIQ7UkO4k9kF7CeGxOL4H0GBKjm zYW6Fjf+M57PtEkLLcmWVgzcgvCb0pZpYSTGbmTkfvWIMJPPbLpUGIkPUqkSN5hnFZan 4fFdxdem5+SLpY0Ll3vieqfbiLvSIJqSwmARXYjPVBtUBzjxiotex7M8lI4KfHfgf9Jd E2bg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=AvtakVJH; spf=pass (google.com: domain of john.stultz@linaro.org designates 209.85.220.65 as permitted sender) smtp.mailfrom=john.stultz@linaro.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from mail-sor-f65.google.com (mail-sor-f65.google.com. [209.85.220.65]) by mx.google.com with SMTPS id cd18sor14774595plb.27.2019.04.24.10.08.54 for (Google Transport Security); Wed, 24 Apr 2019 10:08:54 -0700 (PDT) Received-SPF: pass (google.com: domain of john.stultz@linaro.org designates 209.85.220.65 as permitted sender) client-ip=209.85.220.65; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=AvtakVJH; spf=pass (google.com: domain of john.stultz@linaro.org designates 209.85.220.65 as permitted sender) smtp.mailfrom=john.stultz@linaro.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=Kw97zKx6ijTQMTY8hmHHesW3NQxmgImJerDwv67tN38=; b=AvtakVJH9GjFvEO+6pYWMVfAjWin/3isimRi8bNIupS7xQS2R086ojvSWT5/JMoUga TdMbBDjeQO++m5sXUD2v2KMllYuyzhmcla8PtPgbQvWIIwyhuBnyQWXnJLUKXZVe3pn7 8qXHdzWzMEcPNNwIswKCobouemNbOOUboL8xSD+uk+VE7Sl3vxXEcX74+CssqhtEDeiG SCRhvaGXYXW+cg8EtPhsyNREuN2ET1pZqdoQFmmy0Qe/1D2MlzQsGgNgCrRH5vhzvCim x81EwAavDstySkCOZXM5YIWnfnIahBhZbXprjLAwZosiklnQl6GJzv8SMtFtOUcGZO2T eMDw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=Kw97zKx6ijTQMTY8hmHHesW3NQxmgImJerDwv67tN38=; b=ByDydxTgX+LBNeQi6kvA1R42ZTxZMu8scFgmb7CN/vp2qwpER0wktL6EkkV/OWVrON WHsWrr60RXEqaP6Jjgkw7cPY4wVREp+9cjxSECUd/eCM1+N1e8Tt5oGT12bXmT709Fhz ByHYgWuXOvfxt6eDETqxEczlFpInD5Z5PCSiY1sioIF5wJDV9ivJOHbozkAcGJ35kAiS o/2QA8xbRyZs8GFHOKRi/PJHNcXsZB7FtqPMqcOKlXrooQMjjIwCFdjcBXF0mitS5EYE kp+p0KlC6ZdVTLH90PkmrCLmisbEL5d9OWYvwXy/4gqKrOW95y5nSJXr5wA7EkXfG9z0 bdng== X-Gm-Message-State: APjAAAWGrD4lDqIDesuRe5P6PneAJJYmZ7uAAYN5dsW3skeDoFzwMeYP cvC2Mv2feWRzt0TSCU7iQSEa1rsQ X-Google-Smtp-Source: APXvYqwhHdrTPysllqKY01CrRcX42uZ5LMg1LS+AWQN+Z0rDWHtrXQjq/viL8bTkPk0mhwo/gkY4dw== X-Received: by 2002:a17:902:854c:: with SMTP id d12mr33870818plo.150.1556125733827; Wed, 24 Apr 2019 10:08:53 -0700 (PDT) Return-Path: Received: from localhost.localdomain ([2601:1c2:680:1319:4e72:b9ff:fe99:466a]) by smtp.gmail.com with ESMTPSA id e4sm4425073pfn.185.2019.04.24.10.08.50 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 24 Apr 2019 10:08:52 -0700 (PDT) From: John Stultz To: dri-devel Cc: Adrian Salido , Emil Velikov , Sean Paul , Alistair Strachan , Marissa Wall , John Stultz Subject: [PATCH 5/6 v2] libdrm: reduce number of reallocations in drmModeAtomicAddProperty Date: Wed, 24 Apr 2019 10:08:40 -0700 Message-Id: <1556125721-32145-6-git-send-email-john.stultz@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1556125721-32145-1-git-send-email-john.stultz@linaro.org> References: <1556125721-32145-1-git-send-email-john.stultz@linaro.org> From: Adrian Salido When calling drmModeAtomicAddProperty allocation of memory happens as needed in increments of 16 elements. This can be very slow if there are multiple properties to be updated in an Atomic Commit call. Increase this to as many as can fit in a memory PAGE to avoid having to reallocate memory too often. Also this patch has a small one line perf tweak in drmModeAtomicDuplicate() to only memcpy items to the cursor position in order avoid copying the entire item array if its mostly empty. Cc: Emil Velikov Cc: Sean Paul Cc: Alistair Strachan Cc: Marissa Wall Reviewed-by: Alex Deucher Reviewed-by: Emil Velikov [jstultz: Expanded commit message] Signed-off-by: John Stultz --- v2: Improved commit message --- xf86drmMode.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) -- 2.7.4 diff --git a/xf86drmMode.c b/xf86drmMode.c index 8f8633e..c878d9e 100644 --- a/xf86drmMode.c +++ b/xf86drmMode.c @@ -1259,7 +1259,7 @@ drm_public drmModeAtomicReqPtr drmModeAtomicDuplicate(drmModeAtomicReqPtr old) return NULL; } memcpy(new->items, old->items, - old->size_items * sizeof(*new->items)); + old->cursor * sizeof(*new->items)); } else { new->items = NULL; } @@ -1322,12 +1322,13 @@ drm_public int drmModeAtomicAddProperty(drmModeAtomicReqPtr req, return -EINVAL; if (req->cursor >= req->size_items) { + const uint32_t item_size_inc = getpagesize() / sizeof(*req->items); drmModeAtomicReqItemPtr new; - req->size_items += 16; + req->size_items += item_size_inc; new = realloc(req->items, req->size_items * sizeof(*req->items)); if (!new) { - req->size_items -= 16; + req->size_items -= item_size_inc; return -ENOMEM; } req->items = new;