Skip to contentSkip to conversation

xen: replace complicated tlbflush check with an inline function

PATCH Dongli Zhang 2 participants 2 messages Sep 14, 2016 – Sep 15, 2016

lore
Share & tools
lore
#0 lore raw
Quoted 7 lines

I don't think you should pass this into the function ...

Review

Quoted 3 lines
(quoted diff) +3 -0
+{
+    return page->u.free.need_tlbflush &&
+           page->tlbflush_timestamp <= tlbflush_current_time &&

... and use tlbflush_current_time() here instead.

I rewrite the inline function in xen/include/xen/mm.h to:

+#include <asm/flushtlb.h>
+
+static inline bool accumulate_tlbflush(bool need_tlbflush,
+ const struct page_info *page,
+ uint32_t tlbflush_timestamp)
+{
+ return page->u.free.need_tlbflush &&
+ page->tlbflush_timestamp <= tlbflush_current_time() &&
+ (!need_tlbflush ||
+ page->tlbflush_timestamp > tlbflush_timestamp);
+}

However, to use tlbflush_current_time and "asm/flushtlb.h" would lead to the following compiling error:

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

In file included from /home/zhang/test/mainline-xen/xen/include/asm/flushtlb.h:14:0,

                 from suspend.c:13:
/home/zhang/test/mainline-xen/xen/include/xen/mm.h: In function ‘accumulate_tlbflush’:
/home/zhang/test/mainline-xen/xen/include/xen/mm.h:577:12: error: implicit declaration of function ‘tlbflush_current_time’ [-Werror=implicit-function-declaration]
            page->tlbflush_timestamp <= tlbflush_current_time() &&
            ^

/home/zhang/test/mainline-xen/xen/include/xen/mm.h:577:12: error: nested extern declaration of ‘tlbflush_current_time’ [-Werror=nested-externs]
cc1: all warnings being treated as errors
make[4]: *** [suspend.o] Error 1

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

I can workaround the issue by removing "#include <asm/flushtlb.h>" from xen/arch/x86/acpi/suspend.c and then everything works fine.

Can I just rewrite the inline function to a #define macro? This minimizes the changes to the code.

+#define accumulate_tlbflush(need_tlbflush, page, tlbflush_timestamp) \

+    (page)->u.free.need_tlbflush &&                                  \
+    (page)->tlbflush_timestamp <= tlbflush_current_time() &&         \
+    (!need_tlbflush ||                                               \

+ (page)->tlbflush_timestamp > tlbflush_timestamp)

Thank you very much!

Dongli Zhang

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel

#1 lore raw
Quoted 37 lines
Quoted 8 lines
Quoted 1 line · On 15.09.16 at 00:36, <[email protected]> wrote:

I don't think you should pass this into the function ...

Review

Quoted 3 lines
(quoted diff) +3 -0
+{
+    return page->u.free.need_tlbflush &&
+           page->tlbflush_timestamp <= tlbflush_current_time &&

... and use tlbflush_current_time() here instead.

I rewrite the inline function in xen/include/xen/mm.h to:

(quoted diff) +11 -0
+#include <asm/flushtlb.h>
+
+static inline bool accumulate_tlbflush(bool need_tlbflush,
+                                       const struct page_info *page,
+                                       uint32_t tlbflush_timestamp)
+{
+    return page->u.free.need_tlbflush &&
+           page->tlbflush_timestamp <= tlbflush_current_time() &&
+           (!need_tlbflush ||
+            page->tlbflush_timestamp > tlbflush_timestamp);
+}

However, to use tlbflush_current_time and "asm/flushtlb.h" would lead to the following compiling error:

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

In file included from /home/zhang/test/mainline-xen/xen/include/asm/flushtlb.h:14:0,

                 from suspend.c:13:

/home/zhang/test/mainline-xen/xen/include/xen/mm.h: In function ‘accumulate_tlbflush’:
/home/zhang/test/mainline-xen/xen/include/xen/mm.h:577:12: error: implicit declaration of function ‘tlbflush_current_time’ [-Werror=implicit-function-declaration]

            page->tlbflush_timestamp <= tlbflush_current_time() &&
            ^
Quoted 8 lines

/home/zhang/test/mainline-xen/xen/include/xen/mm.h:577:12: error: nested extern declaration of ‘tlbflush_current_time’ [-Werror=nested-externs]
cc1: all warnings being treated as errors
make[4]: *** [suspend.o] Error 1

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

I can workaround the issue by removing "#include <asm/flushtlb.h>" from xen/arch/x86/acpi/suspend.c and then everything works fine.

Removing? You should _add_ asm/tlbflush.h inclusion to xen/mm.h.

Review

Quoted 9 lines

Can I just rewrite the inline function to a #define macro? This minimizes the
changes to the code.

(quoted diff) +5 -0
+#define accumulate_tlbflush(need_tlbflush, page, tlbflush_timestamp) \
+    (page)->u.free.need_tlbflush &&                                  \
+    (page)->tlbflush_timestamp <= tlbflush_current_time() &&         \
+    (!need_tlbflush ||                                               \
+     (page)->tlbflush_timestamp > tlbflush_timestamp)

Generally we prefer inline functions whenever possible. And note that if for some reason the macro variant would indeed be necessary to us, you'd complete parenthesization of the uses of the various macro parameters. And ideally you'd also avoid evaluating any of the arguments other than exactly once. All of which are a non-issues with inline functions.

Jan

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel