public inbox for kvm@vger.kernel.org
 help / color / mirror / Atom feed
From: Sean Christopherson <seanjc@google.com>
To: Paolo Bonzini <pbonzini@redhat.com>
Cc: kvm@vger.kernel.org, Sean Christopherson <seanjc@google.com>
Subject: [kvm-unit-tests PATCH 3/8] x86: smp: Replace spaces with tabs
Date: Fri, 21 Jan 2022 23:18:47 +0000	[thread overview]
Message-ID: <20220121231852.1439917-4-seanjc@google.com> (raw)
In-Reply-To: <20220121231852.1439917-1-seanjc@google.com>

Replace spaces with tabs in smp.c, and opportunistically clean up a
handful of minor coding style violations.

No functional change intended.

Signed-off-by: Sean Christopherson <seanjc@google.com>
---
 lib/x86/smp.c | 129 +++++++++++++++++++++++++-------------------------
 1 file changed, 64 insertions(+), 65 deletions(-)

diff --git a/lib/x86/smp.c b/lib/x86/smp.c
index 2ac0ef74..b24675fd 100644
--- a/lib/x86/smp.c
+++ b/lib/x86/smp.c
@@ -21,128 +21,127 @@ static atomic_t active_cpus;
 
 static __attribute__((used)) void ipi(void)
 {
-    void (*function)(void *data) = ipi_function;
-    void *data = ipi_data;
-    bool wait = ipi_wait;
+	void (*function)(void *data) = ipi_function;
+	void *data = ipi_data;
+	bool wait = ipi_wait;
 
-    if (!wait) {
-	ipi_done = 1;
-	apic_write(APIC_EOI, 0);
-    }
-    function(data);
-    atomic_dec(&active_cpus);
-    if (wait) {
-	ipi_done = 1;
-	apic_write(APIC_EOI, 0);
-    }
+	if (!wait) {
+		ipi_done = 1;
+		apic_write(APIC_EOI, 0);
+	}
+	function(data);
+	atomic_dec(&active_cpus);
+	if (wait) {
+		ipi_done = 1;
+		apic_write(APIC_EOI, 0);
+	}
 }
 
 asm (
-     "ipi_entry: \n"
-     "   call ipi \n"
+	 "ipi_entry: \n"
+	 "   call ipi \n"
 #ifndef __x86_64__
-     "   iret"
+	 "   iret"
 #else
-     "   iretq"
+	 "   iretq"
 #endif
-     );
+	 );
 
 int cpu_count(void)
 {
-    return _cpu_count;
+	return _cpu_count;
 }
 
 int smp_id(void)
 {
-    unsigned id;
+	unsigned id;
 
-    asm ("mov %%gs:0, %0" : "=r"(id));
-    return id;
+	asm ("mov %%gs:0, %0" : "=r"(id));
+	return id;
 }
 
 static void setup_smp_id(void *data)
 {
-    asm ("mov %0, %%gs:0" : : "r"(apic_id()) : "memory");
+	asm ("mov %0, %%gs:0" : : "r"(apic_id()) : "memory");
 }
 
-static void __on_cpu(int cpu, void (*function)(void *data), void *data,
-                     int wait)
+static void __on_cpu(int cpu, void (*function)(void *data), void *data, int wait)
 {
-    unsigned int target = id_map[cpu];
+	const u32 ipi_icr = APIC_INT_ASSERT | APIC_DEST_PHYSICAL | APIC_DM_FIXED | IPI_VECTOR;
+	unsigned int target = id_map[cpu];
 
-    spin_lock(&ipi_lock);
-    if (target == smp_id())
-	function(data);
-    else {
-	atomic_inc(&active_cpus);
-	ipi_done = 0;
-	ipi_function = function;
-	ipi_data = data;
-	ipi_wait = wait;
-	apic_icr_write(APIC_INT_ASSERT | APIC_DEST_PHYSICAL | APIC_DM_FIXED
-                       | IPI_VECTOR, target);
-	while (!ipi_done)
-	    ;
-    }
-    spin_unlock(&ipi_lock);
+	spin_lock(&ipi_lock);
+	if (target == smp_id()) {
+		function(data);
+	} else {
+		atomic_inc(&active_cpus);
+		ipi_done = 0;
+		ipi_function = function;
+		ipi_data = data;
+		ipi_wait = wait;
+		apic_icr_write(ipi_icr, target);
+		while (!ipi_done)
+			;
+	}
+	spin_unlock(&ipi_lock);
 }
 
 void on_cpu(int cpu, void (*function)(void *data), void *data)
 {
-    __on_cpu(cpu, function, data, 1);
+	__on_cpu(cpu, function, data, 1);
 }
 
 void on_cpu_async(int cpu, void (*function)(void *data), void *data)
 {
-    __on_cpu(cpu, function, data, 0);
+	__on_cpu(cpu, function, data, 0);
 }
 
 void on_cpus(void (*function)(void *data), void *data)
 {
-    int cpu;
+	int cpu;
 
-    for (cpu = cpu_count() - 1; cpu >= 0; --cpu)
-        on_cpu_async(cpu, function, data);
+	for (cpu = cpu_count() - 1; cpu >= 0; --cpu)
+		on_cpu_async(cpu, function, data);
 
-    while (cpus_active() > 1)
-        pause();
+	while (cpus_active() > 1)
+		pause();
 }
 
 int cpus_active(void)
 {
-    return atomic_read(&active_cpus);
+	return atomic_read(&active_cpus);
 }
 
 void smp_init(void)
 {
-    int i;
-    void ipi_entry(void);
+	int i;
+	void ipi_entry(void);
 
-    _cpu_count = fwcfg_get_nb_cpus();
+	_cpu_count = fwcfg_get_nb_cpus();
 
-    setup_idt();
-    init_apic_map();
-    set_idt_entry(IPI_VECTOR, ipi_entry, 0);
+	setup_idt();
+	init_apic_map();
+	set_idt_entry(IPI_VECTOR, ipi_entry, 0);
 
-    setup_smp_id(0);
-    for (i = 1; i < cpu_count(); ++i)
-        on_cpu(i, setup_smp_id, 0);
+	setup_smp_id(0);
+	for (i = 1; i < cpu_count(); ++i)
+		on_cpu(i, setup_smp_id, 0);
 
-    atomic_inc(&active_cpus);
+	atomic_inc(&active_cpus);
 }
 
 static void do_reset_apic(void *data)
 {
-    reset_apic();
+	reset_apic();
 }
 
 void smp_reset_apic(void)
 {
-    int i;
+	int i;
 
-    reset_apic();
-    for (i = 1; i < cpu_count(); ++i)
-        on_cpu(i, do_reset_apic, 0);
+	reset_apic();
+	for (i = 1; i < cpu_count(); ++i)
+		on_cpu(i, do_reset_apic, 0);
 
-    atomic_inc(&active_cpus);
+	atomic_inc(&active_cpus);
 }
-- 
2.35.0.rc0.227.g00780c9af4-goog


  parent reply	other threads:[~2022-01-21 23:19 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-01-21 23:18 [kvm-unit-tests PATCH 0/8] x86: APIC bug fix and cleanup Sean Christopherson
2022-01-21 23:18 ` [kvm-unit-tests PATCH 1/8] x86: Always use legacy xAPIC to get APIC ID during TSS setup Sean Christopherson
2022-01-22  1:18   ` David Matlack
2022-01-21 23:18 ` [kvm-unit-tests PATCH 2/8] x86: nVMX: Load actual GS.base for both guest and host Sean Christopherson
2022-01-21 23:18 ` Sean Christopherson [this message]
2022-01-21 23:18 ` [kvm-unit-tests PATCH 4/8] x86: desc: Replace spaces with tabs Sean Christopherson
2022-01-21 23:18 ` [kvm-unit-tests PATCH 5/8] x86: Add proper helpers for per-cpu reads/writes Sean Christopherson
2022-01-21 23:18 ` [kvm-unit-tests PATCH 6/8] x86: apic: Replace spaces with tabs Sean Christopherson
2022-01-21 23:18 ` [kvm-unit-tests PATCH 7/8] x86: apic: Track APIC ops on a per-cpu basis Sean Christopherson
2022-01-21 23:18 ` [kvm-unit-tests PATCH 8/8] x86: apic: Make xAPIC and I/O APIC pointers static Sean Christopherson

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220121231852.1439917-4-seanjc@google.com \
    --to=seanjc@google.com \
    --cc=kvm@vger.kernel.org \
    --cc=pbonzini@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox