Skip to contentSkip to conversation

x86: UV uv_tlb.c cleanup

PATCH Superseded Cliff Wickman 2 participants 2 messages May 17, 2011

Subsystems (2)

v1 of 6 Superseded Latest is v6 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 x86: UV uv_tlb.c cleanup

General readability cleanup of tlb_uv.c (as promised to Ingo). Now:
- no function has over 50 non-comment lines
- very few statements of over 80 characters need to be broken

Split long functions into shorter logical functions.
Shortened some variable and structure member names.
Added special functions for reads and writes of MMR regs with very long names. Added the 'tunables' table to shortened tunables_write().
Added the 'stat_description' table to shorten uv_ptc_proc_write(). Pass fewer 'stat' arguments where it can be derived from the 'bcp' argument. Function definitions consistent on one line, and inline in few (short) cases. Moved some small structures and an atomic inline function to the header file. Moved some local variables to the blocks where they are used. Updated copyright date.

One logic difference:
Breaking uv_init_per_cpu() into get_cpu_topology() and summarize_uvhub_sockets() actually corrects a possible bug for the theoretical case in which there is a missing socket on a blade. An 'smaster' (socket master) had been expected for every socket.

Diffed against 2.6.39.rc7

---
 arch/x86/include/asm/uv/uv_bau.h |  168 ++++-
 arch/x86/platform/uv/tlb_uv.c    | 1254 +++++++++++++++++++--------------------
 2 files changed, 776 insertions(+), 646 deletions(-)
arch/x86/include/asm/uv/uv_bau.h +146 -22
Index: linux/arch/x86/include/asm/uv/uv_bau.h
===================================================================
@@ -35,9 +35,9 @@
 
 #define MAX_CPUS_PER_UVHUB		64
 #define MAX_CPUS_PER_SOCKET		32
-#define UV_ADP_SIZE			64 /* hardware-provided max. */
-#define UV_CPUS_PER_ACT_STATUS		32 /* hardware-provided max. */
-#define UV_ITEMS_PER_DESCRIPTOR		8
+#define ADP_SZ				64 /* hardware-provided max. */
+#define UV_CPUS_PER_AS			32 /* hardware-provided max. */
+#define ITEMS_PER_DESC			8
 /* the 'throttle' to prevent the hardware stay-busy bug */
 #define MAX_BAU_CONCURRENT		3
 #define UV_ACT_STATUS_MASK		0x3
@@ -48,7 +48,7 @@
 #define UV2_NET_ENDPOINT_INTD		0x28
 #define UV_NET_ENDPOINT_INTD		(is_uv1_hub() ?			\
 			UV1_NET_ENDPOINT_INTD : UV2_NET_ENDPOINT_INTD)
-#define UV_DESC_BASE_PNODE_SHIFT	49
+#define UV_DESC_PSHIFT			49
 #define UV_PAYLOADQ_PNODE_SHIFT		49
 #define UV_PTC_BASENAME			"sgi_uv/ptc_statistics"
 #define UV_BAU_BASENAME			"sgi_uv/bau_tunables"
@@ -85,12 +85,20 @@
 #define BAU_TRANS_MASK 0x3f
 
 /*
+ * shorten some awkward names
+ */
+#define AS_PUSH_SHIFT UVH_LB_BAU_SB_ACTIVATION_CONTROL_PUSH_SHFT
+#define SOFTACK_MSHIFT UVH_LB_BAU_MISC_CONTROL_ENABLE_INTD_SOFT_ACK_MODE_SHFT
+#define SOFTACK_PSHIFT UVH_LB_BAU_MISC_CONTROL_INTD_SOFT_ACK_TIMEOUT_PERIOD_SHFT
+#define SOFTACK_TIMEOUT_PERIOD UV_INTD_SOFT_ACK_TIMEOUT_PERIOD
+
+/*
  * bits in UVH_LB_BAU_SB_ACTIVATION_STATUS_0/1
  */
-#define DESC_STATUS_IDLE		0
-#define DESC_STATUS_ACTIVE		1
-#define DESC_STATUS_DESTINATION_TIMEOUT	2
-#define DESC_STATUS_SOURCE_TIMEOUT	3
+#define DS_IDLE			0
+#define DS_ACTIVE		1
+#define DS_DESTINATION_TIMEOUT	2
+#define DS_SOURCE_TIMEOUT	3
 /*
  * bits put together from HRP_LB_BAU_SB_ACTIVATION_STATUS_0/1/2
  * values 1 and 5 will not occur
@@ -259,7 +267,7 @@ struct bau_msg_header {
 
 	unsigned int rsvd_4:7;	/* must be zero */
 	/* bits 88:82 */
-	unsigned int sw_ack_flag:1;/* software acknowledge flag */
+	unsigned int swack_flag:1;/* software acknowledge flag */
 	/* bit 89 */
 				/* INTD trasactions at destination are to
 				   wait for software acknowledge */
@@ -315,7 +323,7 @@ struct bau_desc {
  * are 32 bytes (2 micropackets) (256 bits) in length, but contain only 17
  * bytes of usable data, including the sw ack vector in byte 15 (bits 127:120)
  * (12 bytes come from bau_msg_payload, 3 from payload_1, 2 from
- *  sw_ack_vector and payload_2)
+ *  swack_vec and payload_2)
  * "Enabling Software Acknowledgment mode (see Section 4.3.3 Software
  *  Acknowledge Processing) also selects 32 byte (17 bytes usable) payload
  *  operation."
@@ -343,7 +351,7 @@ struct bau_payload_queue_entry {
 	unsigned char unused2;		/* not currently using */
 	/* byte 14 */
 
-	unsigned char sw_ack_vector;	/* filled in by the hardware */
+	unsigned char swack_vec;	/* filled in by the hardware */
 	/* byte 15 (bits 127:120) */
 
 	unsigned short sequence;	/* message sequence number */
@@ -361,7 +369,7 @@ struct bau_payload_queue_entry {
 struct msg_desc {
 	struct bau_payload_queue_entry *msg;
 	int msg_slot;
-	int sw_ack_slot;
+	int swack_slot;
 	struct bau_payload_queue_entry *va_queue_first;
 	struct bau_payload_queue_entry *va_queue_last;
 };
@@ -414,10 +422,29 @@ struct ptc_stats {
 	unsigned long d_rcanceled; /* number of messages canceled by resets */
 };
 
+struct tunables {
+	int *tunp;
+	int deflt;
+};
+
 struct hub_and_pnode {
 	short uvhub;
 	short pnode;
 };
+
+struct socket_desc {
+	short num_cpus;
+	short cpu_number[MAX_CPUS_PER_SOCKET];
+};
+
+struct uvhub_desc {
+	unsigned short socket_mask;
+	short num_cpus;
+	short uvhub;
+	short pnode;
+	struct socket_desc socket[2];
+};
+
 /*
  * one per-cpu; to locate the software tables
  */
@@ -452,21 +479,96 @@ struct bau_control {
 	spinlock_t uvhub_lock;
 	spinlock_t queue_lock;
 	/* tunables */
-	int max_bau_concurrent;
-	int max_bau_concurrent_constant;
+	int max_concurr;
+	int max_concurr_const;
 	int plugged_delay;
 	int plugsb4reset;
 	int timeoutsb4reset;
 	int ipi_reset_limit;
 	int complete_threshold;
-	int congested_response_us;
-	int congested_reps;
-	int congested_period;
+	int cong_response_us;
+	int cong_reps;
+	int cong_period;
 	cycles_t period_time;
 	long period_requests;
-	struct hub_and_pnode *target_hub_and_pnode;
+	struct hub_and_pnode *thp;
 };
 
+static unsigned long read_mmr_uv2_status(void)
+{
+	return uv_read_local_mmr(UV2H_LB_BAU_SB_ACTIVATION_STATUS_2);
+}
+
+static void write_mmr_data_broadcast(int pnode, unsigned long mmr_image)
+{
+	uv_write_global_mmr64(pnode, UVH_BAU_DATA_BROADCAST, mmr_image);
+}
+
+static void write_mmr_descriptor_base(int pnode, unsigned long mmr_image)
+{
+	uv_write_global_mmr64(pnode, UVH_LB_BAU_SB_DESCRIPTOR_BASE, mmr_image);
+}
+
+static void write_mmr_activation(unsigned long index)
+{
+	uv_write_local_mmr(UVH_LB_BAU_SB_ACTIVATION_CONTROL, index);
+}
+
+static void write_global_mmr_activation(int pnode, unsigned long mmr_image)
+{
+	uv_write_global_mmr64(pnode, UVH_LB_BAU_SB_ACTIVATION_CONTROL,
+								mmr_image);
+}
+
+static void write_mmr_payload_first(int pnode, unsigned long mmr_image)
+{
+	uv_write_global_mmr64(pnode, UVH_LB_BAU_INTD_PAYLOAD_QUEUE_FIRST,
+								mmr_image);
+}
+
+static void write_mmr_payload_tail(int pnode, unsigned long mmr_image)
+{
+	uv_write_global_mmr64(pnode, UVH_LB_BAU_INTD_PAYLOAD_QUEUE_TAIL,
+								mmr_image);
+}
+
+static void write_mmr_payload_last(int pnode, unsigned long mmr_image)
+{
+	uv_write_global_mmr64(pnode, UVH_LB_BAU_INTD_PAYLOAD_QUEUE_LAST,
+								mmr_image);
+}
+
+static void write_mmr_misc_control(int pnode, unsigned long mmr_image)
+{
+	uv_write_global_mmr64(pnode, UVH_LB_BAU_MISC_CONTROL, mmr_image);
+}
+
+static unsigned long read_mmr_misc_control(int pnode)
+{
+	return uv_read_global_mmr64(pnode, UVH_LB_BAU_MISC_CONTROL);
+}
+
+static void write_mmr_sw_ack(unsigned long mr)
+{
+	uv_write_local_mmr(UVH_LB_BAU_INTD_SOFTWARE_ACKNOWLEDGE_ALIAS, mr);
+}
+
+static unsigned long read_mmr_sw_ack(void)
+{
+	return uv_read_local_mmr(UVH_LB_BAU_INTD_SOFTWARE_ACKNOWLEDGE);
+}
+
+static unsigned long read_global_mmr_sw_ack(int pnode)
+{
+	return uv_read_global_mmr64(pnode,
+					UVH_LB_BAU_INTD_SOFTWARE_ACKNOWLEDGE);
+}
+
+static void write_mmr_data_config(int pnode, unsigned long mr)
+{
+	uv_write_global_mmr64(pnode, UVH_BAU_DATA_CONFIG, mr);
+}
+
 static inline int bau_uvhub_isset(int uvhub, struct bau_target_uvhubmask *dstp)
 {
 	return constant_test_bit(uvhub, &dstp->bits[0]);
@@ -501,7 +603,7 @@ struct atomic_short {
 	short counter;
 };
 
-/**
+/*
  * atomic_read_short - read a short atomic variable
  * @v: pointer of type atomic_short
  *
@@ -512,14 +614,14 @@ static inline int atomic_read_short(cons
 	return v->counter;
 }
 
-/**
- * atomic_add_short_return - add and return a short int
+/*
+ * atom_asr - add and return a short int
  * @i: short value to add
  * @v: pointer of type atomic_short
  *
  * Atomically adds @i to @v and returns @i + @v
  */
-static inline int atomic_add_short_return(short i, struct atomic_short *v)
+static inline int atom_asr(short i, struct atomic_short *v)
 {
 	short __i = i;
 	asm volatile(LOCK_PREFIX "xaddw %0, %1"
@@ -528,4 +630,26 @@ static inline int atomic_add_short_retur
 	return i + __i;
 }
 
+/*
+ * conditionally add 1 to *v, unless *v is >= u
+ * return 0 if we cannot add 1 to *v because it is >= u
+ * return 1 if we can add 1 to *v because it is < u
+ * the add is atomic
+ *
+ * This is close to atomic_add_unless(), but this allows the 'u' value
+ * to be lowered below the current 'v'.  atomic_add_unless can only stop
+ * on equal.
+ */
+static inline int atomic_inc_unless_ge(spinlock_t *lock, atomic_t *v, int u)
+{
+	spin_lock(lock);
+	if (atomic_read(v) >= u) {
+		spin_unlock(lock);
+		return 0;
+	}
+	atomic_inc(v);
+	spin_unlock(lock);
+	return 1;
+}
+
 #endif /* _ASM_X86_UV_UV_BAU_H */
arch/x86/platform/uv/tlb_uv.c +630 -624

1,952 lines not on this page · raw message

#1 lore raw

Ok, looks like some good first steps. I have a few more nits below, of things that occur still quite widely in the UV driver files:

arch/x86/include/asm/uv/uv_bau.h struct bau_control { · line 520

Quoted 4 lines · Cliff Wickman
arch/x86/include/asm/uv/uv_bau.h +4 -0
+static void write_global_mmr_activation(int pnode, unsigned long mmr_image)
+{
+	uv_write_global_mmr64(pnode, UVH_LB_BAU_SB_ACTIVATION_CONTROL,
+								mmr_image);

Please *never* break a line at the end line that just because checkpatch.pl complains.

Instead try to make uv_write_global_mmr64() shorter, it's used in quite a few places!

Something like:

	write_gmmr8()
	write_gmmr64()
	write_lmmr64()

would still be pretty obvious and is a lot shorter! I applied two tricks:

- The 'MMR' is an UV specific term of art *anyway* which you have to know if you are reading this code, so making it 'LMMR' for local and 'GMMR' for global MMRs is an obvious extension to the abbreviation you are using already.

- You do not have to prefix everything with uv_() !! Only APIs you really need to export to other code like the infamous is_uv_system() flag. These functions are used in files named uv_something.c anyway, and 'MMR' is an UV concept, so the uv_ prefix was absolutely unnecessary screen bloat.

Please propagate the uv_ removal to all other places - there's a lot of functions that have it needlessly.

Likewise, you can propagate these concepts to the naming of the other MMR handling functions as well - for example would turn into write_gmmr_activation() - which is nicer to read and type than write_global_mmr_activation().

I think with that and with your other cleanups you have already done the code will already be a lot more readable.

One more request, could you please make structure fields aligned vertically? I.e. use something like:

struct msg_desc {
	struct bau_payload_queue_entry	*msg;
	int				msg_slot;
	int				swack_slot;
	struct bau_payload_queue_entry	*va_queue_first;
	struct bau_payload_queue_entry	*va_queue_last;
};

Have a look at arch/x86/include/asm/processor.h for more examples.

Also, *please* notice and fix too long structure names like the bau_payload_queue_entry above. Commonly used names like that should be tightly named - so for example could it be 'struct bau_pq_entry'? If that's descriptive enough for you then it could be:

struct msg_desc {
	struct bau_pq_entry		*msg;
	int				msg_slot;
	int				swack_slot;
	struct bau_pq_entry		*va_queue_first;
	struct bau_pq_entry		*va_queue_last;
};

Also, what does the 'va_' prefix mean above? Virtual address? Why does 'msg' have no prefix?

Thanks,

Ingo