From patchwork Mon Jul 25 19:23:15 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Umang Jain X-Patchwork-Id: 16770 X-Patchwork-Delegate: umang.jain@ideasonboard.com Return-Path: X-Original-To: parsemail@patchwork.libcamera.org Delivered-To: parsemail@patchwork.libcamera.org Received: from lancelot.ideasonboard.com (lancelot.ideasonboard.com [92.243.16.209]) by patchwork.libcamera.org (Postfix) with ESMTPS id 3842ABE173 for ; Mon, 25 Jul 2022 19:23:34 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id C9A0263316; Mon, 25 Jul 2022 21:23:33 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1658777013; bh=9lE0amTknXsyC7TQgRRPyXW7aTh/R/rja9omnQvnqq8=; h=To:Date:In-Reply-To:References:Subject:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=btj5Kdk8ISvZu0z7tF0vz1XRfkKanUnQqw/ee5WpTgbJ8FeWfEkvEuwkRZOgRtK4u JXWTnz0lttyjKq3iRBgjPIyL2a2NTgMAjeK9fWXICjwczs7rXLdyoybRUZz3+QfdaA 7zwIB5SaTTScAiy5gHy6/0TIwhfd8DDWBwSCSiHIUWh3PIfm6hdt6b3PP63w2kBME/ QIRH19pKn+GLqH4pp3VYDURZ9KeXuDdTfbo7EK0jcGwtQSCul6qK7Ne63d1V7uLQOL FDBCctIIo/NjMGxU5Fc64EnagJK3fjFdjnT5OLq3CeEo1B/W3hUf5cSybn8i3y0I9b V0hOO+sX1Rm7Q== Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id E64186330E for ; Mon, 25 Jul 2022 21:23:30 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="U3yL38X6"; dkim-atps=neutral Received: from perceval.ideasonboard.com (unknown [IPv6:2401:4900:1f3e:f7a:bc8f:12ed:b45f:c35d]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id E7C306D1; Mon, 25 Jul 2022 21:23:29 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1658777010; bh=9lE0amTknXsyC7TQgRRPyXW7aTh/R/rja9omnQvnqq8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=U3yL38X6Rdwn2F9loUZeA++fSyiWgScJF34G0jbe1icutow9SSQRvfMgEl+o6dzco UuDmjwIil22Bjl0m/VecoflIGdgTtAotlaNOq2ZFuQVMLRnNovng5jkyrH/cOxVNm9 3XPETdD9gmo/1VH45MsWVsZcI+ErlI68qaKGOrl4= To: libcamera-devel@lists.libcamera.org Date: Tue, 26 Jul 2022 00:53:15 +0530 Message-Id: <20220725192317.99026-2-umang.jain@ideasonboard.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20220725192317.99026-1-umang.jain@ideasonboard.com> References: <20220725192317.99026-1-umang.jain@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [RFC PATCH 1/3] utils: ipu3-gen-imgu-input: Generate frames with different b/g 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-Patchwork-Original-From: Umang Jain via libcamera-devel From: Umang Jain Reply-To: Umang Jain Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" Differ each input generated frame by background color. This would help us to deterimine how the IMGU statistics generation delay for each frame. Signed-off-by: Umang Jain --- utils/ipu3/ipu3-gen-imgu-input.sh | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/utils/ipu3/ipu3-gen-imgu-input.sh b/utils/ipu3/ipu3-gen-imgu-input.sh index ea0d385d..9e233396 100755 --- a/utils/ipu3/ipu3-gen-imgu-input.sh +++ b/utils/ipu3/ipu3-gen-imgu-input.sh @@ -66,10 +66,14 @@ if [[ -z ${in_size+x} ]] ; then exit 1 fi +colors=(black red green violet yellow orange purple white brown pink gray) + echo "Generating Input file frame-$in_size.raw" for i in `seq 0 $(expr $frame_count - 1)` do - convert -background "#000000" -size $in_size -fill "#ffffff" -pointsize 120 -gravity center label:"Frame $i" frame-$i.ppm + color_index=$(expr $i % ${#colors[@]}) + convert -background "${colors[$color_index]}" -size $in_size -fill "white" \ + -pointsize 120 -gravity center label:"Frame $i" frame-$i.ppm pnm2raw frame-$i.ppm frame-$i.raw ipu3-pack frame-$i.raw - >> frame-$in_size.raw From patchwork Mon Jul 25 19:23:16 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Umang Jain X-Patchwork-Id: 16771 X-Patchwork-Delegate: umang.jain@ideasonboard.com Return-Path: X-Original-To: parsemail@patchwork.libcamera.org Delivered-To: parsemail@patchwork.libcamera.org Received: from lancelot.ideasonboard.com (lancelot.ideasonboard.com [92.243.16.209]) by patchwork.libcamera.org (Postfix) with ESMTPS id 1FEB6BE173 for ; Mon, 25 Jul 2022 19:23:37 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id D788263319; Mon, 25 Jul 2022 21:23:36 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1658777016; bh=yXczEyAmHVtLaX0+gd1hlgvfbGWE9Ruf9KDIPNWdFbw=; h=To:Date:In-Reply-To:References:Subject:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=P5BJi6PE80lFfhsqOI6IdfYkr+FMmVrxmftsk6QOKCiDJo5Ff3GHS7sdws27LuYBa Qw49SQ8wtHUmY9czDVT3hhIL6XrRQ7MI5R0G474ICdgAoYCZmiYrds8yfz2NnlzBtl e1JR95KXM326yQGBCyTHgIeh35yCyHHmryGELJGKzhuNnZc95J7wUn/xosW7PtXitN CSaS2fE2SkrbKrtXk9D9zd+84/JF+vhnkOiv10nJvlSmDYR6K0kFyjSKUgrlO2fy40 OEE09c7NeMFz1T0LHtFvtdKAlgqnh3Oku7qB2Rjt1capgKzgMqaD5FtxUynajP3dL7 7cOXnNDmFX0Bg== Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 823D96330A for ; Mon, 25 Jul 2022 21:23:33 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="NF5b7Qi5"; dkim-atps=neutral Received: from perceval.ideasonboard.com (unknown [IPv6:2401:4900:1f3e:f7a:bc8f:12ed:b45f:c35d]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 7C5DF6D1; Mon, 25 Jul 2022 21:23:32 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1658777013; bh=yXczEyAmHVtLaX0+gd1hlgvfbGWE9Ruf9KDIPNWdFbw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=NF5b7Qi5HRObIgqpEcpjp7Ags4BiRNmZfRRN8EbFK9GUJmASm+ieMoyYyt65M0F7C LfVwWh9f/A5pltFVqO0gZAwZbvFxaO7ISlW6xv0mKOKl3rTsYPOwJdC2ON9+D4W2k3 5vtup9wqZRg+erk7GUgW1t+ckj7n1MYNZsqQOk/E= To: libcamera-devel@lists.libcamera.org Date: Tue, 26 Jul 2022 00:53:16 +0530 Message-Id: <20220725192317.99026-3-umang.jain@ideasonboard.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20220725192317.99026-1-umang.jain@ideasonboard.com> References: <20220725192317.99026-1-umang.jain@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [RFC PATCH 2/3] utils: ipu3: Executable helper to read statistics 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-Patchwork-Original-From: Umang Jain via libcamera-devel From: Umang Jain Reply-To: Umang Jain Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" Usage: ipu3-read-stats input-file output-file [Currently only reads R,G,B averages out of AWB] To be extended to dump more meaningful stats. Signed-off-by: Umang Jain --- utils/ipu3/ipu3-read-stats.c | 110 +++++++++++++++++++++++++++++++++++ utils/ipu3/meson.build | 2 + 2 files changed, 112 insertions(+) create mode 100644 utils/ipu3/ipu3-read-stats.c diff --git a/utils/ipu3/ipu3-read-stats.c b/utils/ipu3/ipu3-read-stats.c new file mode 100644 index 00000000..c400d294 --- /dev/null +++ b/utils/ipu3/ipu3-read-stats.c @@ -0,0 +1,110 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ +/* + * ipu3-read-stats - Dump IPU3 statistics + * + * Copyright 2022 Umang Jain + */ +#define _GNU_SOURCE + +#include +#include +#include +#include +#include +#include +#include + +#include "../../include/linux/intel-ipu3.h" + +static void usage(const char *argv0) +{ + printf("Usage: %s input-file output-file\n", basename(argv0)); + printf("Dump IPU3 statistics\n"); + printf("If the output-file '-', output data will be written to standard output\n"); +} + +int main(int argc, char *argv[]) +{ + int in_fd; + FILE *fout; + int ret; + + if (argc != 3) { + usage(argv[0]); + return 1; + } + + in_fd = open(argv[1], O_RDONLY); + if (in_fd == -1) { + fprintf(stderr, "Failed to open statistics file '%s': %s\n", + argv[1], strerror(errno)); + return 1; + } + + if (strcmp(argv[2], "-") == 0) { + fout = stdout; + } else { + fout = fopen(argv[2], "w"); + if (!fout) { + fprintf(stderr, "Failed to open output file '%s': %s\n", + argv[2], strerror(errno)); + close(in_fd); + return 1; + } + } + + int frame = 0; + struct ipu3_uapi_stats_3a *stats = (struct ipu3_uapi_stats_3a *) malloc(sizeof(struct ipu3_uapi_stats_3a)); + + while (1) { + ret = read(in_fd, stats, sizeof(struct ipu3_uapi_stats_3a)); + if (ret < 0) { + fprintf(stderr, "Failed to read stats data: %s\n", + strerror(errno)); + goto done; + } + + if ((unsigned)ret < sizeof(struct ipu3_uapi_stats_3a)) { + if (ret != 0) + fprintf(stderr, "%u bytes of stray data at end of input\n", + ret); + goto done; + } + + /* ================ Dump AE stats ================ */ + + + /* ================ Dump AWB stats ================ */ + + /* Sum the per-channel averages */ + unsigned int stride_ = 56; /* \todo find dynamic way to calculate grid stride */ + double redSum = 0, greenSum = 0, blueSum = 0; + struct ipu3_uapi_grid_config grid = stats->stats_4a_config.awb_config.grid; + for (unsigned int cellY = 0; cellY < grid.height; cellY++) { + for (unsigned int cellX = 0; cellX < grid.width; cellX++) { + uint32_t cellPosition = cellY * stride_ + cellX; + + const struct ipu3_uapi_awb_set_item *cell = + (const struct ipu3_uapi_awb_set_item *)( + &stats->awb_raw_buffer.meta_data[cellPosition] + ); + const uint8_t G_avg = (cell->Gr_avg + cell->Gb_avg) / 2; + + redSum += cell->R_avg; + greenSum += G_avg; + blueSum += cell->B_avg; + } + } + + fprintf(fout, "Frame: %d, redSum: %.1f, greenSum: %.1f, blueSum: %.1f\n", + frame, redSum, greenSum, blueSum); + frame++; + } + +done: + free(stats); + close(in_fd); + fclose(fout); + + return ret ? 1 : 0; +} diff --git a/utils/ipu3/meson.build b/utils/ipu3/meson.build index c92cc658..88fc2a1b 100644 --- a/utils/ipu3/meson.build +++ b/utils/ipu3/meson.build @@ -2,3 +2,5 @@ ipu3_pack = executable('ipu3-pack', 'ipu3-pack.c') ipu3_unpack = executable('ipu3-unpack', 'ipu3-unpack.c') + +ipu3_read_stats = executable('ipu3-read-stats', 'ipu3-read-stats.c') From patchwork Mon Jul 25 19:23:17 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Umang Jain X-Patchwork-Id: 16772 X-Patchwork-Delegate: umang.jain@ideasonboard.com Return-Path: X-Original-To: parsemail@patchwork.libcamera.org Delivered-To: parsemail@patchwork.libcamera.org Received: from lancelot.ideasonboard.com (lancelot.ideasonboard.com [92.243.16.209]) by patchwork.libcamera.org (Postfix) with ESMTPS id 16DC1BE173 for ; Mon, 25 Jul 2022 19:23:39 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id C39BC63315; Mon, 25 Jul 2022 21:23:38 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1658777018; bh=qFO9CDiF3ZTVw/nIY2glsWHEG/EBVrbg07sl2+XwL1U=; h=To:Date:In-Reply-To:References:Subject:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=SxW8JJFEJpSc30YX9TzdylQl8USgOJw9pd8gY2mBMuqgRSIZ5tCvyzKceYuM4qQHI 1tnTFe83YtLMaWrnQ+T2wJuOh6IYP4aJ70g6OG6fp7pZBhZ7B4Fq9eWtidsV+1Hqc5 gUU0pdwwqiLbY8/APZKq71BZgHG0gUb4pDZH34HpPv7UKAGjS3AIOnfVw46D17qC3g lB7NzH+vfolJ58Wk43oMienHvHetMIxIJr9J6+951bSl1XNU2GvegeGj6Tx5x9ZFdK pwsFeGuWmprUyzIZkbs1oqPZIlb1tvfUwkb8UI9/iOrod7EEGFf9G+zid12ay1PbfS MGcROCTcYXCUQ== Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id AD34363315 for ; Mon, 25 Jul 2022 21:23:36 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="jaQ08GtP"; dkim-atps=neutral Received: from perceval.ideasonboard.com (unknown [IPv6:2401:4900:1f3e:f7a:bc8f:12ed:b45f:c35d]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 9F5046D1; Mon, 25 Jul 2022 21:23:35 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1658777016; bh=qFO9CDiF3ZTVw/nIY2glsWHEG/EBVrbg07sl2+XwL1U=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=jaQ08GtPMnjClxGv6X8SW7SH6RLH17KrIlPMs+G8bYYrsus8WDEG2Hicua2qg0UoA 2Y7NwUQwcP+JnfuoxpwLZFPpjP2VerwLgMfYQijflu/Pat5fCyIEkYw6gl4mwRarJj TopesEDYyZ9Jqobt8NzkzxDnh6NPMolpkAJvDIMg= To: libcamera-devel@lists.libcamera.org Date: Tue, 26 Jul 2022 00:53:17 +0530 Message-Id: <20220725192317.99026-4-umang.jain@ideasonboard.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20220725192317.99026-1-umang.jain@ideasonboard.com> References: <20220725192317.99026-1-umang.jain@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [RFC PATCH 3/3] utils: ipu3: ipu3-process Save generated stats to a file 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-Patchwork-Original-From: Umang Jain via libcamera-devel From: Umang Jain Reply-To: Umang Jain Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" Save generated stats to a file, which can be dumped using ipu3-read-stats utility. Signed-off-by: Umang Jain --- utils/ipu3/ipu3-process.sh | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/utils/ipu3/ipu3-process.sh b/utils/ipu3/ipu3-process.sh index 828a72f8..84f42302 100755 --- a/utils/ipu3/ipu3-process.sh +++ b/utils/ipu3/ipu3-process.sh @@ -83,7 +83,8 @@ process_frames() { --set-fmt-video=pixelformat=$IMGU_OUT_PIXELFORMAT,width=$vf_width,height=$vf_height \ $stream_setting --stream-to=$output_dir/frames-vf.bin & sleep 0.5 - v4l2-ctl -d $($mediactl -e "$imgu_entity 3a stat") $stream_setting & + v4l2-ctl -d $($mediactl -e "$imgu_entity 3a stat") $stream_setting \ + --stream-to=$output_dir/frames-stat.bin & sleep 0.5 # Feed the IMGU input.