aboutsummaryrefslogtreecommitdiff
path: root/miscutils/devfsd.c
diff options
context:
space:
mode:
authorJames Byrne <james.byrne@origamienergy.com>2019-07-02 11:35:03 +0200
committerDenys Vlasenko <vda.linux@googlemail.com>2019-07-02 11:35:03 +0200
commit6937487be73cd4563b876413277a295a5fe2f32c (patch)
treef16cc9999a7c827891e6ec8d99c699fc791008ee /miscutils/devfsd.c
parentcaecfdc20d450686cd1f7e9b5f650322f894b3c2 (diff)
downloadbusybox-w32-6937487be73cd4563b876413277a295a5fe2f32c.tar.gz
busybox-w32-6937487be73cd4563b876413277a295a5fe2f32c.tar.bz2
busybox-w32-6937487be73cd4563b876413277a295a5fe2f32c.zip
libbb: reduce the overhead of single parameter bb_error_msg() calls
Back in 2007, commit 0c97c9d43707 ("'simple' error message functions by Loic Grenie") introduced bb_simple_perror_msg() to allow for a lower overhead call to bb_perror_msg() when only a string was being printed with no parameters. This saves space for some CPU architectures because it avoids the overhead of a call to a variadic function. However there has never been a simple version of bb_error_msg(), and since 2007 many new calls to bb_perror_msg() have been added that only take a single parameter and so could have been using bb_simple_perror_message(). This changeset introduces 'simple' versions of bb_info_msg(), bb_error_msg(), bb_error_msg_and_die(), bb_herror_msg() and bb_herror_msg_and_die(), and replaces all calls that only take a single parameter, or use something like ("%s", arg), with calls to the corresponding 'simple' version. Since it is likely that single parameter calls to the variadic functions may be accidentally reintroduced in the future a new debugging config option WARN_SIMPLE_MSG has been introduced. This uses some macro magic which will cause any such calls to generate a warning, but this is turned off by default to avoid use of the unpleasant macros in normal circumstances. This is a large changeset due to the number of calls that have been replaced. The only files that contain changes other than simple substitution of function calls are libbb.h, libbb/herror_msg.c, libbb/verror_msg.c and libbb/xfuncs_printf.c. In miscutils/devfsd.c, networking/udhcp/common.h and util-linux/mdev.c additonal macros have been added for logging so that single parameter and multiple parameter logging variants exist. The amount of space saved varies considerably by architecture, and was found to be as follows (for 'defconfig' using GCC 7.4): Arm: -92 bytes MIPS: -52 bytes PPC: -1836 bytes x86_64: -938 bytes Note that for the MIPS architecture only an exception had to be made disabling the 'simple' calls for 'udhcp' (in networking/udhcp/common.h) because it made these files larger on MIPS. Signed-off-by: James Byrne <james.byrne@origamienergy.com> Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'miscutils/devfsd.c')
-rw-r--r--miscutils/devfsd.c15
1 files changed, 10 insertions, 5 deletions
diff --git a/miscutils/devfsd.c b/miscutils/devfsd.c
index e4d104d0c..f3d935b2e 100644
--- a/miscutils/devfsd.c
+++ b/miscutils/devfsd.c
@@ -344,14 +344,19 @@ static const char bb_msg_variable_not_found[] ALIGN1 = "variable: %s not found";
344/* Busybox stuff */ 344/* Busybox stuff */
345#if ENABLE_DEVFSD_VERBOSE || ENABLE_DEBUG 345#if ENABLE_DEVFSD_VERBOSE || ENABLE_DEBUG
346#define info_logger(p, fmt, args...) bb_info_msg(fmt, ## args) 346#define info_logger(p, fmt, args...) bb_info_msg(fmt, ## args)
347#define simple_info_logger(p, msg) bb_simple_info_msg(msg)
347#define msg_logger(p, fmt, args...) bb_error_msg(fmt, ## args) 348#define msg_logger(p, fmt, args...) bb_error_msg(fmt, ## args)
349#define simple_msg_logger(p, msg) bb_simple_error_msg(msg)
348#define msg_logger_and_die(p, fmt, args...) bb_error_msg_and_die(fmt, ## args) 350#define msg_logger_and_die(p, fmt, args...) bb_error_msg_and_die(fmt, ## args)
351#define simple_msg_logger_and_die(p, msg) bb_simple_error_msg_and_die(msg)
349#define error_logger(p, fmt, args...) bb_perror_msg(fmt, ## args) 352#define error_logger(p, fmt, args...) bb_perror_msg(fmt, ## args)
350#define error_logger_and_die(p, fmt, args...) bb_perror_msg_and_die(fmt, ## args) 353#define error_logger_and_die(p, fmt, args...) bb_perror_msg_and_die(fmt, ## args)
351#else 354#else
352#define info_logger(p, fmt, args...) 355#define info_logger(p, fmt, args...)
353#define msg_logger(p, fmt, args...) 356#define msg_logger(p, fmt, args...)
357#define simple_msg_logger(p, msg)
354#define msg_logger_and_die(p, fmt, args...) exit(EXIT_FAILURE) 358#define msg_logger_and_die(p, fmt, args...) exit(EXIT_FAILURE)
359#define simple_msg_logger_and_die(p, msg) exit(EXIT_FAILURE)
355#define error_logger(p, fmt, args...) 360#define error_logger(p, fmt, args...)
356#define error_logger_and_die(p, fmt, args...) exit(EXIT_FAILURE) 361#define error_logger_and_die(p, fmt, args...) exit(EXIT_FAILURE)
357#endif 362#endif
@@ -727,7 +732,7 @@ static int do_servicing(int fd, unsigned long event_mask)
727 caught_sighup = FALSE; 732 caught_sighup = FALSE;
728 return c_sighup; 733 return c_sighup;
729 } 734 }
730 msg_logger_and_die(LOG_ERR, "read error on control file"); 735 simple_msg_logger_and_die(LOG_ERR, "read error on control file");
731} /* End Function do_servicing */ 736} /* End Function do_servicing */
732 737
733static void service_name(const struct devfsd_notify_struct *info) 738static void service_name(const struct devfsd_notify_struct *info)
@@ -786,7 +791,7 @@ static void service_name(const struct devfsd_notify_struct *info)
786 action_compat(info, entry->action.what); 791 action_compat(info, entry->action.what);
787 break; 792 break;
788 default: 793 default:
789 msg_logger_and_die(LOG_ERR, "Unknown action"); 794 simple_msg_logger_and_die(LOG_ERR, "Unknown action");
790 } 795 }
791 } 796 }
792} /* End Function service_name */ 797} /* End Function service_name */
@@ -1691,7 +1696,7 @@ int st_expr_expand(char *output, unsigned int length, const char *input,
1691 } 1696 }
1692 return FALSE; 1697 return FALSE;
1693st_expr_expand_out: 1698st_expr_expand_out:
1694 info_logger(LOG_INFO, bb_msg_small_buffer); 1699 simple_info_logger(LOG_INFO, bb_msg_small_buffer);
1695 return FALSE; 1700 return FALSE;
1696} /* End Function st_expr_expand */ 1701} /* End Function st_expr_expand */
1697 1702
@@ -1775,7 +1780,7 @@ static const char *expand_variable(char *buffer, unsigned int length,
1775 return input + len; 1780 return input + len;
1776 } 1781 }
1777 if (ch != ':' || ptr[1] != '-') { 1782 if (ch != ':' || ptr[1] != '-') {
1778 info_logger(LOG_INFO, "illegal char in var name"); 1783 simple_info_logger(LOG_INFO, "illegal char in var name");
1779 return NULL; 1784 return NULL;
1780 } 1785 }
1781 /* It's that handy "${var:-word}" expression. Check if var is defined */ 1786 /* It's that handy "${var:-word}" expression. Check if var is defined */
@@ -1838,7 +1843,7 @@ static const char *expand_variable(char *buffer, unsigned int length,
1838 *out_pos += len; 1843 *out_pos += len;
1839 return input; 1844 return input;
1840expand_variable_out: 1845expand_variable_out:
1841 info_logger(LOG_INFO, bb_msg_small_buffer); 1846 simple_info_logger(LOG_INFO, bb_msg_small_buffer);
1842 return NULL; 1847 return NULL;
1843} /* End Function expand_variable */ 1848} /* End Function expand_variable */
1844 1849