From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 551C042857; Tue, 28 Mar 2023 17:52:34 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 308524021D; Tue, 28 Mar 2023 17:52:34 +0200 (CEST) Received: from mail-pj1-f47.google.com (mail-pj1-f47.google.com [209.85.216.47]) by mails.dpdk.org (Postfix) with ESMTP id 5920040156 for ; Tue, 28 Mar 2023 17:52:32 +0200 (CEST) Received: by mail-pj1-f47.google.com with SMTP id p13-20020a17090a284d00b0023d2e945aebso2004425pjf.0 for ; Tue, 28 Mar 2023 08:52:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=networkplumber-org.20210112.gappssmtp.com; s=20210112; t=1680018751; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:subject:cc:to:from:date:from:to:cc:subject:date :message-id:reply-to; bh=kVz/Ks5gCvFJSGX2mYHL8qjtR8teI+OtHGjT/Wc9/Zg=; b=GmQqIlWKgkUIjhMbyflWvFlnaR6FJxQ4vXc1IDKBYKA6JQyj6Gfll2Rafu19TADVj7 PowSEgHdaIRH238mun6nTbTUJ9RwgtbSb1mZH80H6TCfMq7ZA3oZd7vUyU3RHu8+eg3+ APcmijtwwWcmNYG8EenF0SbRym6agDEDc137edudDsp0+4UcD0MyUGiVkl9ge7lKh4sI i3JytImyQ9JkK3BVYzihExSB3zy1tz5sDi/2HBbJ0enPQUb+wvS5g5aegwZuz2Y++V9q eVVIUCIx6b3YTbn0HpEwXrK7otkFi+6tsSQ8I0KDCxOLSd1GiB3x3xgvkgqSfqSSdCi2 1ukA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680018751; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:subject:cc:to:from:date:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=kVz/Ks5gCvFJSGX2mYHL8qjtR8teI+OtHGjT/Wc9/Zg=; b=Ik1psvGh2BRvKBTYotJuZaLQ1JRzYRDQnwWZTTfC6LAWLQdGd8OLZ47OrNgypUCCxn tGmxUByzyXlZMC0jZC1HnhcVbDy9cuOKVpcERQIHPvxXPlKAYRO90giwX/9CbQhOVVf4 eckFf/UIw0IFWcQNHu9ykcVw/29S79qjZgx5pY/H4ETeAYx+PSBuhMlPKO9i9o6HQdU4 4ao81u+gjtZ9oWhwMxsN+fgZk60gcM8UldkmUn9FbnNMcEUmuA7qilICSXVlWdQY0+WR uPnJTTzwilOXhDi4Pf1XYKxX4CHRKIeN9Xrm2+yvInxiWcmtmytueHoqIe0tr5LkVI/V 9RWQ== X-Gm-Message-State: AAQBX9ddGkxgq8Har4/OE0n0AxsuAD/6ASo0KyouNJXtlWQVrWZTzzo/ B5ZLH75r8h6VRUrihmKaOkv7RQ== X-Google-Smtp-Source: AKy350YE+WYkQl7q+gohvwbiife2Dzgt3pd1k/iLKD/zGjwN+4Wi/FTEUzPy/xH+HlRL5TsG7oQNMw== X-Received: by 2002:a17:902:f54e:b0:1a0:6a47:184e with SMTP id h14-20020a170902f54e00b001a06a47184emr20377940plf.42.1680018751423; Tue, 28 Mar 2023 08:52:31 -0700 (PDT) Received: from hermes.local (204-195-120-218.wavecable.com. [204.195.120.218]) by smtp.gmail.com with ESMTPSA id l6-20020a170902d34600b00198d7b52eefsm21209247plk.257.2023.03.28.08.52.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 28 Mar 2023 08:52:31 -0700 (PDT) Date: Tue, 28 Mar 2023 08:52:29 -0700 From: Stephen Hemminger To: Srikanth Yalavarthi Cc: Anup Prabhu , , , Subject: Re: [PATCH 1/1] app/mldev: add internal function for file read Message-ID: <20230328085229.51e5dc06@hermes.local> In-Reply-To: <20230323152801.27666-1-syalavarthi@marvell.com> References: <20230323152801.27666-1-syalavarthi@marvell.com> MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org On Thu, 23 Mar 2023 08:28:01 -0700 Srikanth Yalavarthi wrote: > + if (fseek(fp, 0, SEEK_END) == 0) { > + file_size = ftell(fp); > + if (file_size == -1) { > + ret = -EIO; > + goto error; > + } > + > + file_buffer = rte_malloc(NULL, file_size, RTE_CACHE_LINE_SIZE); > + if (file_buffer == NULL) { > + ml_err("Failed to allocate memory: %s\n", file); > + ret = -ENOMEM; > + goto error; > + } > + > + if (fseek(fp, 0, SEEK_SET) != 0) { > + ret = -EIO; > + goto error; > + } > + > + if (fread(file_buffer, sizeof(char), file_size, fp) != (unsigned long)file_size) { > + ml_err("Failed to read file : %s\n", file); > + ret = -EIO; > + goto error; > + } > + fclose(fp); > + } else { > + ret = -EIO; > + goto error; > + } > + > + *buffer = file_buffer; > + *size = file_size; > + > + return 0; Granted this only test code, but is the slowest way to do this. Stdio is buffered (in 4K chunks). And using rte_malloc comes from hugepages. Three levels of improvement are possible: 1. don't use rte_malloc() use malloc() instead. 2. use direct system call for I/O 3. use mmap() to directly map in the file instead read