block, bfq: print SHARED instead of pid for shared queues in logs
authorFrancesco Pollicino <fra.fra.800@gmail.com>
Tue, 12 Mar 2019 08:59:33 +0000 (09:59 +0100)
committerJens Axboe <axboe@kernel.dk>
Mon, 1 Apr 2019 14:15:40 +0000 (08:15 -0600)
The function "bfq_log_bfqq" prints the pid of the process
associated with the queue passed as input.

Unfortunately, if the queue is shared, then more than one process
is associated with the queue. The pid that gets printed in this
case is the pid of one of the associated processes.
Which process gets printed depends on the exact sequence of merge
events the queue underwent. So printing such a pid is rather
useless and above all is often rather confusing because it
reports a random pid between those of the associated processes.

This commit addresses this issue by printing SHARED instead of a pid
if the queue is shared.

Tested-by: Holger Hoffstätte <holger@applied-asynchrony.com>
Tested-by: Oleksandr Natalenko <oleksandr@natalenko.name>
Signed-off-by: Francesco Pollicino <fra.fra.800@gmail.com>
Signed-off-by: Paolo Valente <paolo.valente@linaro.org>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
block/bfq-iosched.c
block/bfq-iosched.h

index 49bde428f7f25680be18772456c9b63494e5fd5b..37cc8f127cf672faafb28ecaf0f391c257817a40 100644 (file)
@@ -2590,6 +2590,16 @@ bfq_merge_bfqqs(struct bfq_data *bfqd, struct bfq_io_cq *bic,
         *   assignment causes no harm).
         */
        new_bfqq->bic = NULL;
+       /*
+        * If the queue is shared, the pid is the pid of one of the associated
+        * processes. Which pid depends on the exact sequence of merge events
+        * the queue underwent. So printing such a pid is useless and confusing
+        * because it reports a random pid between those of the associated
+        * processes.
+        * We mark such a queue with a pid -1, and then print SHARED instead of
+        * a pid in logging messages.
+        */
+       new_bfqq->pid = -1;
        bfqq->bic = NULL;
        /* release process reference to bfqq */
        bfq_put_queue(bfqq);
index 829730b96fb2cd5bb6c5a3ae5c74027465d1622b..67e63c276c7ac5c82ad73bd8a63d6b23e988416e 100644 (file)
@@ -32,6 +32,8 @@
 #define BFQ_DEFAULT_GRP_IOPRIO 0
 #define BFQ_DEFAULT_GRP_CLASS  IOPRIO_CLASS_BE
 
+#define MAX_PID_STR_LENGTH 12
+
 /*
  * Soft real-time applications are extremely more latency sensitive
  * than interactive ones. Over-raise the weight of the former to
@@ -1016,13 +1018,23 @@ void bfq_add_bfqq_busy(struct bfq_data *bfqd, struct bfq_queue *bfqq);
 /* --------------- end of interface of B-WF2Q+ ---------------- */
 
 /* Logging facilities. */
+static inline void bfq_pid_to_str(int pid, char *str, int len)
+{
+       if (pid != -1)
+               snprintf(str, len, "%d", pid);
+       else
+               snprintf(str, len, "SHARED-");
+}
+
 #ifdef CONFIG_BFQ_GROUP_IOSCHED
 struct bfq_group *bfqq_group(struct bfq_queue *bfqq);
 
 #define bfq_log_bfqq(bfqd, bfqq, fmt, args...) do {                    \
+       char pid_str[MAX_PID_STR_LENGTH];       \
+       bfq_pid_to_str((bfqq)->pid, pid_str, MAX_PID_STR_LENGTH);       \
        blk_add_cgroup_trace_msg((bfqd)->queue,                         \
                        bfqg_to_blkg(bfqq_group(bfqq))->blkcg,          \
-                       "bfq%d%c " fmt, (bfqq)->pid,                    \
+                       "bfq%s%c " fmt, pid_str,                        \
                        bfq_bfqq_sync((bfqq)) ? 'S' : 'A', ##args);     \
 } while (0)
 
@@ -1033,10 +1045,13 @@ struct bfq_group *bfqq_group(struct bfq_queue *bfqq);
 
 #else /* CONFIG_BFQ_GROUP_IOSCHED */
 
-#define bfq_log_bfqq(bfqd, bfqq, fmt, args...) \
-       blk_add_trace_msg((bfqd)->queue, "bfq%d%c " fmt, (bfqq)->pid,   \
+#define bfq_log_bfqq(bfqd, bfqq, fmt, args...) do {    \
+       char pid_str[MAX_PID_STR_LENGTH];       \
+       bfq_pid_to_str((bfqq)->pid, pid_str, MAX_PID_STR_LENGTH);       \
+       blk_add_trace_msg((bfqd)->queue, "bfq%s%c " fmt, pid_str,       \
                        bfq_bfqq_sync((bfqq)) ? 'S' : 'A',              \
-                               ##args)
+                               ##args);        \
+} while (0)
 #define bfq_log_bfqg(bfqd, bfqg, fmt, args...)         do {} while (0)
 
 #endif /* CONFIG_BFQ_GROUP_IOSCHED */