From patchwork Thu Jan 30 15:41:37 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naushir Patuck X-Patchwork-Id: 2760 Return-Path: Received: from mail-wm1-x343.google.com (mail-wm1-x343.google.com [IPv6:2a00:1450:4864:20::343]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 5080960448 for ; Thu, 30 Jan 2020 16:43:55 +0100 (CET) Received: by mail-wm1-x343.google.com with SMTP id s144so6717897wme.1 for ; Thu, 30 Jan 2020 07:43:55 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=raspberrypi.com; s=google; h=from:to:cc:subject:date:message-id; bh=3lXELgRwE5w9jrzZiFusyN5XF4WyCPj2oRa3E7euEGo=; b=hQ1xJM36TOwvi9G1fX9ce1W2zubWL+1SM09rRrputUugpiD2Z92yvspa4R4cwFwCX+ TfcNYEPEfkMZsw/gf8M+l6vwiUkFnZIXfhNQjMJqjpcMra6PXAXlH9OuVxdST6XHQNbt 9SyyegK3hOTPo3XyaEGo+bg2gq7iK/tyYuulZG+5j3YfIdpDeFTlXCKgs5izCPoWEzvw SVh1w0y/ED8BXCuj0+QK7sWd/WS5TtNIrZmpHRqCIXzE5lnUSycfYps/uXsT23y1t74V h0LV4Qx5FJHoBpxpFKz62QmSa1YPOC0NSb4rOLMWhqCyQCgZKGGkGKzJ3F8g1Ua4hHWT 2dCg== 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; bh=3lXELgRwE5w9jrzZiFusyN5XF4WyCPj2oRa3E7euEGo=; b=tw2yn6AoNMRIUKOPf3cmyoS9VONwQPOoH+ZCtH7xI8gN2Eg2DtZEvjnTY+ibA05F8K n8AzMzBuoCXaEAwJozNqN0Rek3w2rLLC0689AU4tSXNr1Um7ew4ui+xZUHP9BXhYKwJ+ bpO4JIZiV0PC+OJYsIRxDzFv0ulbAfNUNvxXN3WtrbaTKnQlgBxIs0sJxeK3gT/BbUTt tduPLoHccmaW7ZyuKTxK3vVmZqozgOwRf46fxlsLRM0oEnyz3CNwWoGzz2E6ajM5Pd4i KFNW1C0kDvC2Sg9wAwmtTgJ6jLB9AuMTS8QN4vGJc6FZbkhSZqPCYbFcr+e3VZg9KtHf wunA== X-Gm-Message-State: APjAAAWGd4QLenpUx4k+cnmxHwOq2JIQO5kOpqGesMdRfnlPRZB/e+ob 2yYfoS5+XPZAfep3ZqUYDhqGjmVWaMR7cQ== X-Google-Smtp-Source: APXvYqyaq1KfaccxegaAtW/XeViMamBaVNVEjU4MIWDHIsrNJnN6DcUxmszPXI072Mml+bmugC+FOA== X-Received: by 2002:a7b:cb97:: with SMTP id m23mr6015167wmi.37.1580399034648; Thu, 30 Jan 2020 07:43:54 -0800 (PST) Received: from naushir-VirtualBox.pitowers.org (cust51-dsl50.idnet.net. [212.69.50.51]) by smtp.gmail.com with ESMTPSA id c4sm6736663wml.7.2020.01.30.07.43.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 30 Jan 2020 07:43:54 -0800 (PST) From: naush@raspberrypi.com To: libcamera-devel@lists.libcamera.org Date: Thu, 30 Jan 2020 15:41:37 +0000 Message-Id: <20200130154137.10315-1-naush@raspberrypi.com> X-Mailer: git-send-email 2.17.1 Subject: [libcamera-devel] [PATCH] libcamera: v4l2_videodevice: Fix V4L2 buffer cache entry availabity check X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 30 Jan 2020 15:43:55 -0000 From: Naushir Patuck The logic for keeping track of the cache holding dmabuf file descriptors did not distinguish between slots that are occuiped but free and slots that are not occupied. In devices using imported dmabufs this would result in ping-ponging between the top two cache entries - and that in turn would result in unnecessary cache missies. Fix this by tracking if an entry is occupied separately from if an entry is free. Fixes: 9e71540ebbde ("libcamera: v4l2_videodevice: Add V4L2BufferCache to deal with index mapping") Signed-off-by: Naushir Patuck --- src/libcamera/include/v4l2_videodevice.h | 1 + src/libcamera/v4l2_videodevice.cpp | 6 +++--- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/libcamera/include/v4l2_videodevice.h b/src/libcamera/include/v4l2_videodevice.h index e4d35ab..a77b62e 100644 --- a/src/libcamera/include/v4l2_videodevice.h +++ b/src/libcamera/include/v4l2_videodevice.h @@ -125,6 +125,7 @@ private: bool operator==(const FrameBuffer &buffer); bool free; + bool occupied; private: struct Plane { diff --git a/src/libcamera/v4l2_videodevice.cpp b/src/libcamera/v4l2_videodevice.cpp index 37b8d33..b887a38 100644 --- a/src/libcamera/v4l2_videodevice.cpp +++ b/src/libcamera/v4l2_videodevice.cpp @@ -212,7 +212,7 @@ int V4L2BufferCache::get(const FrameBuffer &buffer) if (!entry.free) continue; - if (use < 0) + if (use < 0 && !entry.occupied) use = index; /* Try to find a cache hit by comparing the planes. */ @@ -245,12 +245,12 @@ void V4L2BufferCache::put(unsigned int index) } V4L2BufferCache::Entry::Entry() - : free(true) + : free(true), occupied(false) { } V4L2BufferCache::Entry::Entry(bool free, const FrameBuffer &buffer) - : free(free) + : free(free), occupied(true) { for (const FrameBuffer::Plane &plane : buffer.planes()) planes_.emplace_back(plane);