* [PATCH 1/2] linux/printk.h: drop unused log_entry::dummy member
@ 2023-08-04 8:11 Ahmad Fatoum
2023-08-04 8:11 ` [PATCH 2/2] console: allocate only once instead of twice per log message Ahmad Fatoum
2023-08-04 8:31 ` [PATCH 1/2] linux/printk.h: drop unused log_entry::dummy member Sascha Hauer
0 siblings, 2 replies; 3+ messages in thread
From: Ahmad Fatoum @ 2023-08-04 8:11 UTC (permalink / raw)
To: barebox; +Cc: Ahmad Fatoum
The pointer is used no where, so let's save that space.
Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
include/linux/printk.h | 1 -
1 file changed, 1 deletion(-)
diff --git a/include/linux/printk.h b/include/linux/printk.h
index 978e853bab48..76cdb15d5b4c 100644
--- a/include/linux/printk.h
+++ b/include/linux/printk.h
@@ -149,7 +149,6 @@ int __pr_memory_display(int level, const void *addr, loff_t offs, unsigned nbyte
struct log_entry {
struct list_head list;
char *msg;
- void *dummy;
uint64_t timestamp;
int level;
};
--
2.39.2
^ permalink raw reply [flat|nested] 3+ messages in thread
* [PATCH 2/2] console: allocate only once instead of twice per log message
2023-08-04 8:11 [PATCH 1/2] linux/printk.h: drop unused log_entry::dummy member Ahmad Fatoum
@ 2023-08-04 8:11 ` Ahmad Fatoum
2023-08-04 8:31 ` [PATCH 1/2] linux/printk.h: drop unused log_entry::dummy member Sascha Hauer
1 sibling, 0 replies; 3+ messages in thread
From: Ahmad Fatoum @ 2023-08-04 8:11 UTC (permalink / raw)
To: barebox; +Cc: Ahmad Fatoum
We do two allocations for each log message, one for the log message
string itself and another for the struct log_entry referencing it.
We could just make the log message directly follow the log entry and
save the space for the pointer and the time to do a second allocation.
No functional change.
Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
common/console_common.c | 14 +++++++-------
include/linux/printk.h | 2 +-
2 files changed, 8 insertions(+), 8 deletions(-)
diff --git a/common/console_common.c b/common/console_common.c
index 866a7cbf65dc..c78581299248 100644
--- a/common/console_common.c
+++ b/common/console_common.c
@@ -10,6 +10,7 @@
#include <errno.h>
#include <console.h>
#include <init.h>
+#include <string.h>
#include <environment.h>
#include <globalvar.h>
#include <magicvar.h>
@@ -19,6 +20,7 @@
#include <malloc.h>
#include <linux/pstore.h>
#include <linux/math64.h>
+#include <linux/overflow.h>
#ifndef CONFIG_CONSOLE_NONE
@@ -39,7 +41,6 @@ static int barebox_log_max_messages = 1000;
static void log_del(struct log_entry *log)
{
- free(log->msg);
list_del(&log->list);
free(log);
barebox_logbuf_num_messages--;
@@ -89,15 +90,14 @@ static void pr_puts(int level, const char *str)
log_clean(barebox_log_max_messages - 1);
if (barebox_log_max_messages >= 0) {
- log = malloc(sizeof(*log));
+ int msglen;
+
+ msglen = strlen(str);
+ log = malloc(struct_size(log, msg, msglen + 1));
if (!log)
goto nolog;
- log->msg = strdup(str);
- if (!log->msg) {
- free(log);
- goto nolog;
- }
+ memcpy(log->msg, str, msglen + 1);
log->timestamp = get_time_ns();
log->level = level;
diff --git a/include/linux/printk.h b/include/linux/printk.h
index 76cdb15d5b4c..cd4c3cb68edb 100644
--- a/include/linux/printk.h
+++ b/include/linux/printk.h
@@ -148,9 +148,9 @@ int __pr_memory_display(int level, const void *addr, loff_t offs, unsigned nbyte
struct log_entry {
struct list_head list;
- char *msg;
uint64_t timestamp;
int level;
+ char msg[];
};
extern struct list_head barebox_logbuf;
--
2.39.2
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH 1/2] linux/printk.h: drop unused log_entry::dummy member
2023-08-04 8:11 [PATCH 1/2] linux/printk.h: drop unused log_entry::dummy member Ahmad Fatoum
2023-08-04 8:11 ` [PATCH 2/2] console: allocate only once instead of twice per log message Ahmad Fatoum
@ 2023-08-04 8:31 ` Sascha Hauer
1 sibling, 0 replies; 3+ messages in thread
From: Sascha Hauer @ 2023-08-04 8:31 UTC (permalink / raw)
To: Ahmad Fatoum; +Cc: barebox
On Fri, Aug 04, 2023 at 10:11:46AM +0200, Ahmad Fatoum wrote:
> The pointer is used no where, so let's save that space.
>
> Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
> ---
> include/linux/printk.h | 1 -
> 1 file changed, 1 deletion(-)
Applied, thanks
Sascha
>
> diff --git a/include/linux/printk.h b/include/linux/printk.h
> index 978e853bab48..76cdb15d5b4c 100644
> --- a/include/linux/printk.h
> +++ b/include/linux/printk.h
> @@ -149,7 +149,6 @@ int __pr_memory_display(int level, const void *addr, loff_t offs, unsigned nbyte
> struct log_entry {
> struct list_head list;
> char *msg;
> - void *dummy;
> uint64_t timestamp;
> int level;
> };
> --
> 2.39.2
>
>
>
--
Pengutronix e.K. | |
Steuerwalder Str. 21 | http://www.pengutronix.de/ |
31137 Hildesheim, Germany | Phone: +49-5121-206917-0 |
Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 |
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2023-08-04 8:33 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-08-04 8:11 [PATCH 1/2] linux/printk.h: drop unused log_entry::dummy member Ahmad Fatoum
2023-08-04 8:11 ` [PATCH 2/2] console: allocate only once instead of twice per log message Ahmad Fatoum
2023-08-04 8:31 ` [PATCH 1/2] linux/printk.h: drop unused log_entry::dummy member Sascha Hauer
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox