dlog_logger: get rid of Android Logger throttling 53/289853/3
authorMichal Bloch <m.bloch@samsung.com>
Tue, 14 Mar 2023 16:33:56 +0000 (17:33 +0100)
committerMichal Bloch <m.bloch@samsung.com>
Fri, 24 Mar 2023 15:51:33 +0000 (16:51 +0100)
No longer needed now that each reader has its own thread,
since it won't starve other threads.

Change-Id: I90477fcd1510b9447027fc0f1bcfd67b45305514
Signed-off-by: Michal Bloch <m.bloch@samsung.com>
src/logger/logger.c
src/logger/logger_internal.h
src/logger/reader_logger.c

index 7cab684..735d658 100644 (file)
@@ -397,9 +397,9 @@ int service_writer_kmsg(struct logger *server, struct writer *wr, struct epoll_e
         * than the daemon could process them, which would then necessitate some
         * sort of throttling. In practice, KMSG doesn't really get flooded with
         * logs the same way Android Logger devices are so the throttling is mostly
-        * there because we get it for free anyway and consistency doesn't hurt. */
+        * there because we got it for free anyway. */
 
-       int max_loop_iterations = g_backend.logger_device_throttling[LOG_ID_KMSG];
+       int max_loop_iterations = g_backend.kmsg_throttling;
        while (max_loop_iterations--) {
                int r = read(wr->fd_entity.fd, wr->buffer, sizeof wr->buffer - 1);
 
@@ -776,7 +776,6 @@ int prepare_config_data(struct logger_config_data *data)
 
        const dlogutil_sorting_order_e sort_by = get_order_from_config(&conf);
 
-       int throttling_default = log_config_get_int(&conf, "logger_dev_throttling", LOGGER_DEVICE_THROTTLING_DEFAULT);
        const char *const dynamic_config_dir = log_config_get(&conf, DYNAMIC_CONFIG_CONF_KEY);
 
        const char * const backend = log_config_claim_backend(&conf);
@@ -790,14 +789,7 @@ int prepare_config_data(struct logger_config_data *data)
                goto end;
        }
 
-       for (int i = 0; i < LOG_ID_MAX; i++) {
-               char key[MAX_CONF_KEY_LEN];
-               const int r = snprintf(key, sizeof key, "logger_dev_throttling_%s", log_name_by_id((log_id_t)i));
-               if (r < 0)
-                       continue;
-
-               g_backend.logger_device_throttling[i] = max_int(1, log_config_get_int(&conf, key, throttling_default));
-       }
+       g_backend.kmsg_throttling = max_int(1, log_config_get_int(&conf, "logger_dev_throttling_kmsg", LOGGER_DEVICE_THROTTLING_DEFAULT));
 
        if (dynamic_config_dir && dynamic_config_dir[0] == '/') {
                data->dynamic_config_dir = strdup(dynamic_config_dir);
index 6b00247..ddf7b56 100644 (file)
@@ -90,7 +90,7 @@ enum {
 extern struct backend_data {
        bool use_logger_by_default;
        char logger_devices[LOG_ID_MAX][MAX_CONF_VAL_LEN];
-       int logger_device_throttling[LOG_ID_MAX];
+       int kmsg_throttling;
        struct reader_logger *logger_readers[LOG_ID_MAX];
 
        /* Lazy polling is Android Logger specific, since in that case
index 0861575..f887958 100644 (file)
@@ -80,15 +80,7 @@ static int service_reader_logger(struct reader_common *_reader, struct now_t tim
        struct reader_logger *const reader = (struct reader_logger *) _reader;
        assert(reader);
 
-       /* The devices for the Android Logger only return one log per read().
-        * So using an 'if' here would be wasteful and, more importantly, too slow in the case where other logs come in.
-        * However, with an unlimited loop, if there are extreme amounts of logs incoming,
-        * the loop handles them slower than they come so the program stays in the loop
-        * for a very long time, starving all other log sources. Using a limited loop
-        * makes sure that the daemon works efficiently in the usual case while preventing
-        * starvation under heavy load. */
-       int max_loop_iterations = g_backend.logger_device_throttling[reader->buf_id];
-       while (max_loop_iterations--) {
+       while (true) {
                /* Note, nominally we had been polling the source FD entity and not
                 * `device_fd`, but that is the same FD (see the init and free ops).
                 * This is temporary redundancy due to the migration to threads. */