tlb_uv.c 46 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709
  1. /*
  2. * SGI UltraViolet TLB flush routines.
  3. *
  4. * (c) 2008-2010 Cliff Wickman <cpw@sgi.com>, SGI.
  5. *
  6. * This code is released under the GNU General Public License version 2 or
  7. * later.
  8. */
  9. #include <linux/seq_file.h>
  10. #include <linux/proc_fs.h>
  11. #include <linux/debugfs.h>
  12. #include <linux/kernel.h>
  13. #include <linux/slab.h>
  14. #include <linux/delay.h>
  15. #include <asm/mmu_context.h>
  16. #include <asm/uv/uv.h>
  17. #include <asm/uv/uv_mmrs.h>
  18. #include <asm/uv/uv_hub.h>
  19. #include <asm/uv/uv_bau.h>
  20. #include <asm/apic.h>
  21. #include <asm/idle.h>
  22. #include <asm/tsc.h>
  23. #include <asm/irq_vectors.h>
  24. #include <asm/timer.h>
  25. /* timeouts in nanoseconds (indexed by UVH_AGING_PRESCALE_SEL urgency7 30:28) */
  26. static int timeout_base_ns[] = {
  27. 20,
  28. 160,
  29. 1280,
  30. 10240,
  31. 81920,
  32. 655360,
  33. 5242880,
  34. 167772160
  35. };
  36. static int timeout_us;
  37. static int nobau;
  38. static int baudisabled;
  39. static spinlock_t disable_lock;
  40. static cycles_t congested_cycles;
  41. /* tunables: */
  42. static int max_bau_concurrent = MAX_BAU_CONCURRENT;
  43. static int max_bau_concurrent_constant = MAX_BAU_CONCURRENT;
  44. static int plugged_delay = PLUGGED_DELAY;
  45. static int plugsb4reset = PLUGSB4RESET;
  46. static int timeoutsb4reset = TIMEOUTSB4RESET;
  47. static int ipi_reset_limit = IPI_RESET_LIMIT;
  48. static int complete_threshold = COMPLETE_THRESHOLD;
  49. static int congested_response_us = CONGESTED_RESPONSE_US;
  50. static int congested_reps = CONGESTED_REPS;
  51. static int congested_period = CONGESTED_PERIOD;
  52. static struct dentry *tunables_dir;
  53. static struct dentry *tunables_file;
  54. static int __init setup_nobau(char *arg)
  55. {
  56. nobau = 1;
  57. return 0;
  58. }
  59. early_param("nobau", setup_nobau);
  60. /* base pnode in this partition */
  61. static int uv_partition_base_pnode __read_mostly;
  62. /* position of pnode (which is nasid>>1): */
  63. static int uv_nshift __read_mostly;
  64. static unsigned long uv_mmask __read_mostly;
  65. static DEFINE_PER_CPU(struct ptc_stats, ptcstats);
  66. static DEFINE_PER_CPU(struct bau_control, bau_control);
  67. static DEFINE_PER_CPU(cpumask_var_t, uv_flush_tlb_mask);
  68. /*
  69. * Determine the first node on a uvhub. 'Nodes' are used for kernel
  70. * memory allocation.
  71. */
  72. static int __init uvhub_to_first_node(int uvhub)
  73. {
  74. int node, b;
  75. for_each_online_node(node) {
  76. b = uv_node_to_blade_id(node);
  77. if (uvhub == b)
  78. return node;
  79. }
  80. return -1;
  81. }
  82. /*
  83. * Determine the apicid of the first cpu on a uvhub.
  84. */
  85. static int __init uvhub_to_first_apicid(int uvhub)
  86. {
  87. int cpu;
  88. for_each_present_cpu(cpu)
  89. if (uvhub == uv_cpu_to_blade_id(cpu))
  90. return per_cpu(x86_cpu_to_apicid, cpu);
  91. return -1;
  92. }
  93. /*
  94. * Free a software acknowledge hardware resource by clearing its Pending
  95. * bit. This will return a reply to the sender.
  96. * If the message has timed out, a reply has already been sent by the
  97. * hardware but the resource has not been released. In that case our
  98. * clear of the Timeout bit (as well) will free the resource. No reply will
  99. * be sent (the hardware will only do one reply per message).
  100. */
  101. static inline void uv_reply_to_message(struct msg_desc *mdp,
  102. struct bau_control *bcp)
  103. {
  104. unsigned long dw;
  105. struct bau_payload_queue_entry *msg;
  106. msg = mdp->msg;
  107. if (!msg->canceled) {
  108. dw = (msg->sw_ack_vector << UV_SW_ACK_NPENDING) |
  109. msg->sw_ack_vector;
  110. uv_write_local_mmr(
  111. UVH_LB_BAU_INTD_SOFTWARE_ACKNOWLEDGE_ALIAS, dw);
  112. }
  113. msg->replied_to = 1;
  114. msg->sw_ack_vector = 0;
  115. }
  116. /*
  117. * Process the receipt of a RETRY message
  118. */
  119. static inline void uv_bau_process_retry_msg(struct msg_desc *mdp,
  120. struct bau_control *bcp)
  121. {
  122. int i;
  123. int cancel_count = 0;
  124. int slot2;
  125. unsigned long msg_res;
  126. unsigned long mmr = 0;
  127. struct bau_payload_queue_entry *msg;
  128. struct bau_payload_queue_entry *msg2;
  129. struct ptc_stats *stat;
  130. msg = mdp->msg;
  131. stat = bcp->statp;
  132. stat->d_retries++;
  133. /*
  134. * cancel any message from msg+1 to the retry itself
  135. */
  136. for (msg2 = msg+1, i = 0; i < DEST_Q_SIZE; msg2++, i++) {
  137. if (msg2 > mdp->va_queue_last)
  138. msg2 = mdp->va_queue_first;
  139. if (msg2 == msg)
  140. break;
  141. /* same conditions for cancellation as uv_do_reset */
  142. if ((msg2->replied_to == 0) && (msg2->canceled == 0) &&
  143. (msg2->sw_ack_vector) && ((msg2->sw_ack_vector &
  144. msg->sw_ack_vector) == 0) &&
  145. (msg2->sending_cpu == msg->sending_cpu) &&
  146. (msg2->msg_type != MSG_NOOP)) {
  147. slot2 = msg2 - mdp->va_queue_first;
  148. mmr = uv_read_local_mmr
  149. (UVH_LB_BAU_INTD_SOFTWARE_ACKNOWLEDGE);
  150. msg_res = msg2->sw_ack_vector;
  151. /*
  152. * This is a message retry; clear the resources held
  153. * by the previous message only if they timed out.
  154. * If it has not timed out we have an unexpected
  155. * situation to report.
  156. */
  157. if (mmr & (msg_res << UV_SW_ACK_NPENDING)) {
  158. /*
  159. * is the resource timed out?
  160. * make everyone ignore the cancelled message.
  161. */
  162. msg2->canceled = 1;
  163. stat->d_canceled++;
  164. cancel_count++;
  165. uv_write_local_mmr(
  166. UVH_LB_BAU_INTD_SOFTWARE_ACKNOWLEDGE_ALIAS,
  167. (msg_res << UV_SW_ACK_NPENDING) |
  168. msg_res);
  169. }
  170. }
  171. }
  172. if (!cancel_count)
  173. stat->d_nocanceled++;
  174. }
  175. /*
  176. * Do all the things a cpu should do for a TLB shootdown message.
  177. * Other cpu's may come here at the same time for this message.
  178. */
  179. static void uv_bau_process_message(struct msg_desc *mdp,
  180. struct bau_control *bcp)
  181. {
  182. int msg_ack_count;
  183. short socket_ack_count = 0;
  184. struct ptc_stats *stat;
  185. struct bau_payload_queue_entry *msg;
  186. struct bau_control *smaster = bcp->socket_master;
  187. /*
  188. * This must be a normal message, or retry of a normal message
  189. */
  190. msg = mdp->msg;
  191. stat = bcp->statp;
  192. if (msg->address == TLB_FLUSH_ALL) {
  193. local_flush_tlb();
  194. stat->d_alltlb++;
  195. } else {
  196. __flush_tlb_one(msg->address);
  197. stat->d_onetlb++;
  198. }
  199. stat->d_requestee++;
  200. /*
  201. * One cpu on each uvhub has the additional job on a RETRY
  202. * of releasing the resource held by the message that is
  203. * being retried. That message is identified by sending
  204. * cpu number.
  205. */
  206. if (msg->msg_type == MSG_RETRY && bcp == bcp->uvhub_master)
  207. uv_bau_process_retry_msg(mdp, bcp);
  208. /*
  209. * This is a sw_ack message, so we have to reply to it.
  210. * Count each responding cpu on the socket. This avoids
  211. * pinging the count's cache line back and forth between
  212. * the sockets.
  213. */
  214. socket_ack_count = atomic_add_short_return(1, (struct atomic_short *)
  215. &smaster->socket_acknowledge_count[mdp->msg_slot]);
  216. if (socket_ack_count == bcp->cpus_in_socket) {
  217. /*
  218. * Both sockets dump their completed count total into
  219. * the message's count.
  220. */
  221. smaster->socket_acknowledge_count[mdp->msg_slot] = 0;
  222. msg_ack_count = atomic_add_short_return(socket_ack_count,
  223. (struct atomic_short *)&msg->acknowledge_count);
  224. if (msg_ack_count == bcp->cpus_in_uvhub) {
  225. /*
  226. * All cpus in uvhub saw it; reply
  227. */
  228. uv_reply_to_message(mdp, bcp);
  229. }
  230. }
  231. return;
  232. }
  233. /*
  234. * Determine the first cpu on a uvhub.
  235. */
  236. static int uvhub_to_first_cpu(int uvhub)
  237. {
  238. int cpu;
  239. for_each_present_cpu(cpu)
  240. if (uvhub == uv_cpu_to_blade_id(cpu))
  241. return cpu;
  242. return -1;
  243. }
  244. /*
  245. * Last resort when we get a large number of destination timeouts is
  246. * to clear resources held by a given cpu.
  247. * Do this with IPI so that all messages in the BAU message queue
  248. * can be identified by their nonzero sw_ack_vector field.
  249. *
  250. * This is entered for a single cpu on the uvhub.
  251. * The sender want's this uvhub to free a specific message's
  252. * sw_ack resources.
  253. */
  254. static void
  255. uv_do_reset(void *ptr)
  256. {
  257. int i;
  258. int slot;
  259. int count = 0;
  260. unsigned long mmr;
  261. unsigned long msg_res;
  262. struct bau_control *bcp;
  263. struct reset_args *rap;
  264. struct bau_payload_queue_entry *msg;
  265. struct ptc_stats *stat;
  266. bcp = &per_cpu(bau_control, smp_processor_id());
  267. rap = (struct reset_args *)ptr;
  268. stat = bcp->statp;
  269. stat->d_resets++;
  270. /*
  271. * We're looking for the given sender, and
  272. * will free its sw_ack resource.
  273. * If all cpu's finally responded after the timeout, its
  274. * message 'replied_to' was set.
  275. */
  276. for (msg = bcp->va_queue_first, i = 0; i < DEST_Q_SIZE; msg++, i++) {
  277. /* uv_do_reset: same conditions for cancellation as
  278. uv_bau_process_retry_msg() */
  279. if ((msg->replied_to == 0) &&
  280. (msg->canceled == 0) &&
  281. (msg->sending_cpu == rap->sender) &&
  282. (msg->sw_ack_vector) &&
  283. (msg->msg_type != MSG_NOOP)) {
  284. /*
  285. * make everyone else ignore this message
  286. */
  287. msg->canceled = 1;
  288. slot = msg - bcp->va_queue_first;
  289. count++;
  290. /*
  291. * only reset the resource if it is still pending
  292. */
  293. mmr = uv_read_local_mmr
  294. (UVH_LB_BAU_INTD_SOFTWARE_ACKNOWLEDGE);
  295. msg_res = msg->sw_ack_vector;
  296. if (mmr & msg_res) {
  297. stat->d_rcanceled++;
  298. uv_write_local_mmr(
  299. UVH_LB_BAU_INTD_SOFTWARE_ACKNOWLEDGE_ALIAS,
  300. (msg_res << UV_SW_ACK_NPENDING) |
  301. msg_res);
  302. }
  303. }
  304. }
  305. return;
  306. }
  307. /*
  308. * Use IPI to get all target uvhubs to release resources held by
  309. * a given sending cpu number.
  310. */
  311. static void uv_reset_with_ipi(struct bau_target_uvhubmask *distribution,
  312. int sender)
  313. {
  314. int uvhub;
  315. int cpu;
  316. cpumask_t mask;
  317. struct reset_args reset_args;
  318. reset_args.sender = sender;
  319. cpus_clear(mask);
  320. /* find a single cpu for each uvhub in this distribution mask */
  321. for (uvhub = 0;
  322. uvhub < sizeof(struct bau_target_uvhubmask) * BITSPERBYTE;
  323. uvhub++) {
  324. if (!bau_uvhub_isset(uvhub, distribution))
  325. continue;
  326. /* find a cpu for this uvhub */
  327. cpu = uvhub_to_first_cpu(uvhub);
  328. cpu_set(cpu, mask);
  329. }
  330. /* IPI all cpus; Preemption is already disabled */
  331. smp_call_function_many(&mask, uv_do_reset, (void *)&reset_args, 1);
  332. return;
  333. }
  334. static inline unsigned long
  335. cycles_2_us(unsigned long long cyc)
  336. {
  337. unsigned long long ns;
  338. unsigned long us;
  339. ns = (cyc * per_cpu(cyc2ns, smp_processor_id()))
  340. >> CYC2NS_SCALE_FACTOR;
  341. us = ns / 1000;
  342. return us;
  343. }
  344. /*
  345. * wait for all cpus on this hub to finish their sends and go quiet
  346. * leaves uvhub_quiesce set so that no new broadcasts are started by
  347. * bau_flush_send_and_wait()
  348. */
  349. static inline void
  350. quiesce_local_uvhub(struct bau_control *hmaster)
  351. {
  352. atomic_add_short_return(1, (struct atomic_short *)
  353. &hmaster->uvhub_quiesce);
  354. }
  355. /*
  356. * mark this quiet-requestor as done
  357. */
  358. static inline void
  359. end_uvhub_quiesce(struct bau_control *hmaster)
  360. {
  361. atomic_add_short_return(-1, (struct atomic_short *)
  362. &hmaster->uvhub_quiesce);
  363. }
  364. /*
  365. * Wait for completion of a broadcast software ack message
  366. * return COMPLETE, RETRY(PLUGGED or TIMEOUT) or GIVEUP
  367. */
  368. static int uv_wait_completion(struct bau_desc *bau_desc,
  369. unsigned long mmr_offset, int right_shift, int this_cpu,
  370. struct bau_control *bcp, struct bau_control *smaster, long try)
  371. {
  372. unsigned long descriptor_status;
  373. cycles_t ttime;
  374. struct ptc_stats *stat = bcp->statp;
  375. struct bau_control *hmaster;
  376. hmaster = bcp->uvhub_master;
  377. /* spin on the status MMR, waiting for it to go idle */
  378. while ((descriptor_status = (((unsigned long)
  379. uv_read_local_mmr(mmr_offset) >>
  380. right_shift) & UV_ACT_STATUS_MASK)) !=
  381. DESC_STATUS_IDLE) {
  382. /*
  383. * Our software ack messages may be blocked because there are
  384. * no swack resources available. As long as none of them
  385. * has timed out hardware will NACK our message and its
  386. * state will stay IDLE.
  387. */
  388. if (descriptor_status == DESC_STATUS_SOURCE_TIMEOUT) {
  389. stat->s_stimeout++;
  390. return FLUSH_GIVEUP;
  391. } else if (descriptor_status ==
  392. DESC_STATUS_DESTINATION_TIMEOUT) {
  393. stat->s_dtimeout++;
  394. ttime = get_cycles();
  395. /*
  396. * Our retries may be blocked by all destination
  397. * swack resources being consumed, and a timeout
  398. * pending. In that case hardware returns the
  399. * ERROR that looks like a destination timeout.
  400. */
  401. if (cycles_2_us(ttime - bcp->send_message) <
  402. timeout_us) {
  403. bcp->conseccompletes = 0;
  404. return FLUSH_RETRY_PLUGGED;
  405. }
  406. bcp->conseccompletes = 0;
  407. return FLUSH_RETRY_TIMEOUT;
  408. } else {
  409. /*
  410. * descriptor_status is still BUSY
  411. */
  412. cpu_relax();
  413. }
  414. }
  415. bcp->conseccompletes++;
  416. return FLUSH_COMPLETE;
  417. }
  418. static inline cycles_t
  419. sec_2_cycles(unsigned long sec)
  420. {
  421. unsigned long ns;
  422. cycles_t cyc;
  423. ns = sec * 1000000000;
  424. cyc = (ns << CYC2NS_SCALE_FACTOR)/(per_cpu(cyc2ns, smp_processor_id()));
  425. return cyc;
  426. }
  427. /*
  428. * conditionally add 1 to *v, unless *v is >= u
  429. * return 0 if we cannot add 1 to *v because it is >= u
  430. * return 1 if we can add 1 to *v because it is < u
  431. * the add is atomic
  432. *
  433. * This is close to atomic_add_unless(), but this allows the 'u' value
  434. * to be lowered below the current 'v'. atomic_add_unless can only stop
  435. * on equal.
  436. */
  437. static inline int atomic_inc_unless_ge(spinlock_t *lock, atomic_t *v, int u)
  438. {
  439. spin_lock(lock);
  440. if (atomic_read(v) >= u) {
  441. spin_unlock(lock);
  442. return 0;
  443. }
  444. atomic_inc(v);
  445. spin_unlock(lock);
  446. return 1;
  447. }
  448. /*
  449. * Our retries are blocked by all destination swack resources being
  450. * in use, and a timeout is pending. In that case hardware immediately
  451. * returns the ERROR that looks like a destination timeout.
  452. */
  453. static void
  454. destination_plugged(struct bau_desc *bau_desc, struct bau_control *bcp,
  455. struct bau_control *hmaster, struct ptc_stats *stat)
  456. {
  457. udelay(bcp->plugged_delay);
  458. bcp->plugged_tries++;
  459. if (bcp->plugged_tries >= bcp->plugsb4reset) {
  460. bcp->plugged_tries = 0;
  461. quiesce_local_uvhub(hmaster);
  462. spin_lock(&hmaster->queue_lock);
  463. uv_reset_with_ipi(&bau_desc->distribution, bcp->cpu);
  464. spin_unlock(&hmaster->queue_lock);
  465. end_uvhub_quiesce(hmaster);
  466. bcp->ipi_attempts++;
  467. stat->s_resets_plug++;
  468. }
  469. }
  470. static void
  471. destination_timeout(struct bau_desc *bau_desc, struct bau_control *bcp,
  472. struct bau_control *hmaster, struct ptc_stats *stat)
  473. {
  474. hmaster->max_bau_concurrent = 1;
  475. bcp->timeout_tries++;
  476. if (bcp->timeout_tries >= bcp->timeoutsb4reset) {
  477. bcp->timeout_tries = 0;
  478. quiesce_local_uvhub(hmaster);
  479. spin_lock(&hmaster->queue_lock);
  480. uv_reset_with_ipi(&bau_desc->distribution, bcp->cpu);
  481. spin_unlock(&hmaster->queue_lock);
  482. end_uvhub_quiesce(hmaster);
  483. bcp->ipi_attempts++;
  484. stat->s_resets_timeout++;
  485. }
  486. }
  487. /*
  488. * Completions are taking a very long time due to a congested numalink
  489. * network.
  490. */
  491. static void
  492. disable_for_congestion(struct bau_control *bcp, struct ptc_stats *stat)
  493. {
  494. int tcpu;
  495. struct bau_control *tbcp;
  496. /* let only one cpu do this disabling */
  497. spin_lock(&disable_lock);
  498. if (!baudisabled && bcp->period_requests &&
  499. ((bcp->period_time / bcp->period_requests) > congested_cycles)) {
  500. /* it becomes this cpu's job to turn on the use of the
  501. BAU again */
  502. baudisabled = 1;
  503. bcp->set_bau_off = 1;
  504. bcp->set_bau_on_time = get_cycles() +
  505. sec_2_cycles(bcp->congested_period);
  506. stat->s_bau_disabled++;
  507. for_each_present_cpu(tcpu) {
  508. tbcp = &per_cpu(bau_control, tcpu);
  509. tbcp->baudisabled = 1;
  510. }
  511. }
  512. spin_unlock(&disable_lock);
  513. }
  514. /**
  515. * uv_flush_send_and_wait
  516. *
  517. * Send a broadcast and wait for it to complete.
  518. *
  519. * The flush_mask contains the cpus the broadcast is to be sent to including
  520. * cpus that are on the local uvhub.
  521. *
  522. * Returns 0 if all flushing represented in the mask was done.
  523. * Returns 1 if it gives up entirely and the original cpu mask is to be
  524. * returned to the kernel.
  525. */
  526. int uv_flush_send_and_wait(struct bau_desc *bau_desc,
  527. struct cpumask *flush_mask, struct bau_control *bcp)
  528. {
  529. int right_shift;
  530. int completion_status = 0;
  531. int seq_number = 0;
  532. long try = 0;
  533. int cpu = bcp->uvhub_cpu;
  534. int this_cpu = bcp->cpu;
  535. unsigned long mmr_offset;
  536. unsigned long index;
  537. cycles_t time1;
  538. cycles_t time2;
  539. cycles_t elapsed;
  540. struct ptc_stats *stat = bcp->statp;
  541. struct bau_control *smaster = bcp->socket_master;
  542. struct bau_control *hmaster = bcp->uvhub_master;
  543. if (!atomic_inc_unless_ge(&hmaster->uvhub_lock,
  544. &hmaster->active_descriptor_count,
  545. hmaster->max_bau_concurrent)) {
  546. stat->s_throttles++;
  547. do {
  548. cpu_relax();
  549. } while (!atomic_inc_unless_ge(&hmaster->uvhub_lock,
  550. &hmaster->active_descriptor_count,
  551. hmaster->max_bau_concurrent));
  552. }
  553. while (hmaster->uvhub_quiesce)
  554. cpu_relax();
  555. if (cpu < UV_CPUS_PER_ACT_STATUS) {
  556. mmr_offset = UVH_LB_BAU_SB_ACTIVATION_STATUS_0;
  557. right_shift = cpu * UV_ACT_STATUS_SIZE;
  558. } else {
  559. mmr_offset = UVH_LB_BAU_SB_ACTIVATION_STATUS_1;
  560. right_shift =
  561. ((cpu - UV_CPUS_PER_ACT_STATUS) * UV_ACT_STATUS_SIZE);
  562. }
  563. time1 = get_cycles();
  564. do {
  565. if (try == 0) {
  566. bau_desc->header.msg_type = MSG_REGULAR;
  567. seq_number = bcp->message_number++;
  568. } else {
  569. bau_desc->header.msg_type = MSG_RETRY;
  570. stat->s_retry_messages++;
  571. }
  572. bau_desc->header.sequence = seq_number;
  573. index = (1UL << UVH_LB_BAU_SB_ACTIVATION_CONTROL_PUSH_SHFT) |
  574. bcp->uvhub_cpu;
  575. bcp->send_message = get_cycles();
  576. uv_write_local_mmr(UVH_LB_BAU_SB_ACTIVATION_CONTROL, index);
  577. try++;
  578. completion_status = uv_wait_completion(bau_desc, mmr_offset,
  579. right_shift, this_cpu, bcp, smaster, try);
  580. if (completion_status == FLUSH_RETRY_PLUGGED) {
  581. destination_plugged(bau_desc, bcp, hmaster, stat);
  582. } else if (completion_status == FLUSH_RETRY_TIMEOUT) {
  583. destination_timeout(bau_desc, bcp, hmaster, stat);
  584. }
  585. if (bcp->ipi_attempts >= bcp->ipi_reset_limit) {
  586. bcp->ipi_attempts = 0;
  587. completion_status = FLUSH_GIVEUP;
  588. break;
  589. }
  590. cpu_relax();
  591. } while ((completion_status == FLUSH_RETRY_PLUGGED) ||
  592. (completion_status == FLUSH_RETRY_TIMEOUT));
  593. time2 = get_cycles();
  594. bcp->plugged_tries = 0;
  595. bcp->timeout_tries = 0;
  596. if ((completion_status == FLUSH_COMPLETE) &&
  597. (bcp->conseccompletes > bcp->complete_threshold) &&
  598. (hmaster->max_bau_concurrent <
  599. hmaster->max_bau_concurrent_constant))
  600. hmaster->max_bau_concurrent++;
  601. while (hmaster->uvhub_quiesce)
  602. cpu_relax();
  603. atomic_dec(&hmaster->active_descriptor_count);
  604. if (time2 > time1) {
  605. elapsed = time2 - time1;
  606. stat->s_time += elapsed;
  607. if ((completion_status == FLUSH_COMPLETE) && (try == 1)) {
  608. bcp->period_requests++;
  609. bcp->period_time += elapsed;
  610. if ((elapsed > congested_cycles) &&
  611. (bcp->period_requests > bcp->congested_reps)) {
  612. disable_for_congestion(bcp, stat);
  613. }
  614. }
  615. } else
  616. stat->s_requestor--;
  617. if (completion_status == FLUSH_COMPLETE && try > 1)
  618. stat->s_retriesok++;
  619. else if (completion_status == FLUSH_GIVEUP) {
  620. stat->s_giveup++;
  621. return 1;
  622. }
  623. return 0;
  624. }
  625. /**
  626. * uv_flush_tlb_others - globally purge translation cache of a virtual
  627. * address or all TLB's
  628. * @cpumask: mask of all cpu's in which the address is to be removed
  629. * @mm: mm_struct containing virtual address range
  630. * @va: virtual address to be removed (or TLB_FLUSH_ALL for all TLB's on cpu)
  631. * @cpu: the current cpu
  632. *
  633. * This is the entry point for initiating any UV global TLB shootdown.
  634. *
  635. * Purges the translation caches of all specified processors of the given
  636. * virtual address, or purges all TLB's on specified processors.
  637. *
  638. * The caller has derived the cpumask from the mm_struct. This function
  639. * is called only if there are bits set in the mask. (e.g. flush_tlb_page())
  640. *
  641. * The cpumask is converted into a uvhubmask of the uvhubs containing
  642. * those cpus.
  643. *
  644. * Note that this function should be called with preemption disabled.
  645. *
  646. * Returns NULL if all remote flushing was done.
  647. * Returns pointer to cpumask if some remote flushing remains to be
  648. * done. The returned pointer is valid till preemption is re-enabled.
  649. */
  650. const struct cpumask *uv_flush_tlb_others(const struct cpumask *cpumask,
  651. struct mm_struct *mm,
  652. unsigned long va, unsigned int cpu)
  653. {
  654. int locals = 0;
  655. int remotes = 0;
  656. int hubs = 0;
  657. int tcpu;
  658. int tpnode;
  659. struct bau_desc *bau_desc;
  660. struct cpumask *flush_mask;
  661. struct ptc_stats *stat;
  662. struct bau_control *bcp;
  663. struct bau_control *tbcp;
  664. struct hub_and_pnode *hpp;
  665. /* kernel was booted 'nobau' */
  666. if (nobau)
  667. return cpumask;
  668. bcp = &per_cpu(bau_control, cpu);
  669. stat = bcp->statp;
  670. /* bau was disabled due to slow response */
  671. if (bcp->baudisabled) {
  672. /* the cpu that disabled it must re-enable it */
  673. if (bcp->set_bau_off) {
  674. if (get_cycles() >= bcp->set_bau_on_time) {
  675. stat->s_bau_reenabled++;
  676. baudisabled = 0;
  677. for_each_present_cpu(tcpu) {
  678. tbcp = &per_cpu(bau_control, tcpu);
  679. tbcp->baudisabled = 0;
  680. tbcp->period_requests = 0;
  681. tbcp->period_time = 0;
  682. }
  683. }
  684. }
  685. return cpumask;
  686. }
  687. /*
  688. * Each sending cpu has a per-cpu mask which it fills from the caller's
  689. * cpu mask. All cpus are converted to uvhubs and copied to the
  690. * activation descriptor.
  691. */
  692. flush_mask = (struct cpumask *)per_cpu(uv_flush_tlb_mask, cpu);
  693. /* don't actually do a shootdown of the local cpu */
  694. cpumask_andnot(flush_mask, cpumask, cpumask_of(cpu));
  695. if (cpu_isset(cpu, *cpumask))
  696. stat->s_ntargself++;
  697. bau_desc = bcp->descriptor_base;
  698. bau_desc += UV_ITEMS_PER_DESCRIPTOR * bcp->uvhub_cpu;
  699. bau_uvhubs_clear(&bau_desc->distribution, UV_DISTRIBUTION_SIZE);
  700. for_each_cpu(tcpu, flush_mask) {
  701. /*
  702. * The distribution vector is a bit map of pnodes, relative
  703. * to the partition base pnode (and the partition base nasid
  704. * in the header).
  705. * Translate cpu to pnode and hub using an array stored
  706. * in local memory.
  707. */
  708. hpp = &bcp->socket_master->target_hub_and_pnode[tcpu];
  709. tpnode = hpp->pnode - bcp->partition_base_pnode;
  710. bau_uvhub_set(tpnode, &bau_desc->distribution);
  711. if (hpp->uvhub == bcp->uvhub)
  712. locals++;
  713. else
  714. remotes++;
  715. }
  716. if ((locals + remotes) == 0)
  717. return NULL;
  718. stat->s_requestor++;
  719. stat->s_ntargcpu += remotes + locals;
  720. stat->s_ntargremotes += remotes;
  721. stat->s_ntarglocals += locals;
  722. remotes = bau_uvhub_weight(&bau_desc->distribution);
  723. /* uvhub statistics */
  724. hubs = bau_uvhub_weight(&bau_desc->distribution);
  725. if (locals) {
  726. stat->s_ntarglocaluvhub++;
  727. stat->s_ntargremoteuvhub += (hubs - 1);
  728. } else
  729. stat->s_ntargremoteuvhub += hubs;
  730. stat->s_ntarguvhub += hubs;
  731. if (hubs >= 16)
  732. stat->s_ntarguvhub16++;
  733. else if (hubs >= 8)
  734. stat->s_ntarguvhub8++;
  735. else if (hubs >= 4)
  736. stat->s_ntarguvhub4++;
  737. else if (hubs >= 2)
  738. stat->s_ntarguvhub2++;
  739. else
  740. stat->s_ntarguvhub1++;
  741. bau_desc->payload.address = va;
  742. bau_desc->payload.sending_cpu = cpu;
  743. /*
  744. * uv_flush_send_and_wait returns 0 if all cpu's were messaged,
  745. * or 1 if it gave up and the original cpumask should be returned.
  746. */
  747. if (!uv_flush_send_and_wait(bau_desc, flush_mask, bcp))
  748. return NULL;
  749. else
  750. return cpumask;
  751. }
  752. /*
  753. * The BAU message interrupt comes here. (registered by set_intr_gate)
  754. * See entry_64.S
  755. *
  756. * We received a broadcast assist message.
  757. *
  758. * Interrupts are disabled; this interrupt could represent
  759. * the receipt of several messages.
  760. *
  761. * All cores/threads on this hub get this interrupt.
  762. * The last one to see it does the software ack.
  763. * (the resource will not be freed until noninterruptable cpus see this
  764. * interrupt; hardware may timeout the s/w ack and reply ERROR)
  765. */
  766. void uv_bau_message_interrupt(struct pt_regs *regs)
  767. {
  768. int count = 0;
  769. cycles_t time_start;
  770. struct bau_payload_queue_entry *msg;
  771. struct bau_control *bcp;
  772. struct ptc_stats *stat;
  773. struct msg_desc msgdesc;
  774. time_start = get_cycles();
  775. bcp = &per_cpu(bau_control, smp_processor_id());
  776. stat = bcp->statp;
  777. msgdesc.va_queue_first = bcp->va_queue_first;
  778. msgdesc.va_queue_last = bcp->va_queue_last;
  779. msg = bcp->bau_msg_head;
  780. while (msg->sw_ack_vector) {
  781. count++;
  782. msgdesc.msg_slot = msg - msgdesc.va_queue_first;
  783. msgdesc.sw_ack_slot = ffs(msg->sw_ack_vector) - 1;
  784. msgdesc.msg = msg;
  785. uv_bau_process_message(&msgdesc, bcp);
  786. msg++;
  787. if (msg > msgdesc.va_queue_last)
  788. msg = msgdesc.va_queue_first;
  789. bcp->bau_msg_head = msg;
  790. }
  791. stat->d_time += (get_cycles() - time_start);
  792. if (!count)
  793. stat->d_nomsg++;
  794. else if (count > 1)
  795. stat->d_multmsg++;
  796. ack_APIC_irq();
  797. }
  798. /*
  799. * uv_enable_timeouts
  800. *
  801. * Each target uvhub (i.e. a uvhub that has no cpu's) needs to have
  802. * shootdown message timeouts enabled. The timeout does not cause
  803. * an interrupt, but causes an error message to be returned to
  804. * the sender.
  805. */
  806. static void __init uv_enable_timeouts(void)
  807. {
  808. int uvhub;
  809. int nuvhubs;
  810. int pnode;
  811. unsigned long mmr_image;
  812. nuvhubs = uv_num_possible_blades();
  813. for (uvhub = 0; uvhub < nuvhubs; uvhub++) {
  814. if (!uv_blade_nr_possible_cpus(uvhub))
  815. continue;
  816. pnode = uv_blade_to_pnode(uvhub);
  817. mmr_image =
  818. uv_read_global_mmr64(pnode, UVH_LB_BAU_MISC_CONTROL);
  819. /*
  820. * Set the timeout period and then lock it in, in three
  821. * steps; captures and locks in the period.
  822. *
  823. * To program the period, the SOFT_ACK_MODE must be off.
  824. */
  825. mmr_image &= ~((unsigned long)1 <<
  826. UVH_LB_BAU_MISC_CONTROL_ENABLE_INTD_SOFT_ACK_MODE_SHFT);
  827. uv_write_global_mmr64
  828. (pnode, UVH_LB_BAU_MISC_CONTROL, mmr_image);
  829. /*
  830. * Set the 4-bit period.
  831. */
  832. mmr_image &= ~((unsigned long)0xf <<
  833. UVH_LB_BAU_MISC_CONTROL_INTD_SOFT_ACK_TIMEOUT_PERIOD_SHFT);
  834. mmr_image |= (UV_INTD_SOFT_ACK_TIMEOUT_PERIOD <<
  835. UVH_LB_BAU_MISC_CONTROL_INTD_SOFT_ACK_TIMEOUT_PERIOD_SHFT);
  836. uv_write_global_mmr64
  837. (pnode, UVH_LB_BAU_MISC_CONTROL, mmr_image);
  838. /*
  839. * Subsequent reversals of the timebase bit (3) cause an
  840. * immediate timeout of one or all INTD resources as
  841. * indicated in bits 2:0 (7 causes all of them to timeout).
  842. */
  843. mmr_image |= ((unsigned long)1 <<
  844. UVH_LB_BAU_MISC_CONTROL_ENABLE_INTD_SOFT_ACK_MODE_SHFT);
  845. uv_write_global_mmr64
  846. (pnode, UVH_LB_BAU_MISC_CONTROL, mmr_image);
  847. }
  848. }
  849. static void *uv_ptc_seq_start(struct seq_file *file, loff_t *offset)
  850. {
  851. if (*offset < num_possible_cpus())
  852. return offset;
  853. return NULL;
  854. }
  855. static void *uv_ptc_seq_next(struct seq_file *file, void *data, loff_t *offset)
  856. {
  857. (*offset)++;
  858. if (*offset < num_possible_cpus())
  859. return offset;
  860. return NULL;
  861. }
  862. static void uv_ptc_seq_stop(struct seq_file *file, void *data)
  863. {
  864. }
  865. static inline unsigned long long
  866. microsec_2_cycles(unsigned long microsec)
  867. {
  868. unsigned long ns;
  869. unsigned long long cyc;
  870. ns = microsec * 1000;
  871. cyc = (ns << CYC2NS_SCALE_FACTOR)/(per_cpu(cyc2ns, smp_processor_id()));
  872. return cyc;
  873. }
  874. /*
  875. * Display the statistics thru /proc.
  876. * 'data' points to the cpu number
  877. */
  878. static int uv_ptc_seq_show(struct seq_file *file, void *data)
  879. {
  880. struct ptc_stats *stat;
  881. int cpu;
  882. cpu = *(loff_t *)data;
  883. if (!cpu) {
  884. seq_printf(file,
  885. "# cpu sent stime self locals remotes ncpus localhub ");
  886. seq_printf(file,
  887. "remotehub numuvhubs numuvhubs16 numuvhubs8 ");
  888. seq_printf(file,
  889. "numuvhubs4 numuvhubs2 numuvhubs1 dto ");
  890. seq_printf(file,
  891. "retries rok resetp resett giveup sto bz throt ");
  892. seq_printf(file,
  893. "sw_ack recv rtime all ");
  894. seq_printf(file,
  895. "one mult none retry canc nocan reset rcan ");
  896. seq_printf(file,
  897. "disable enable\n");
  898. }
  899. if (cpu < num_possible_cpus() && cpu_online(cpu)) {
  900. stat = &per_cpu(ptcstats, cpu);
  901. /* source side statistics */
  902. seq_printf(file,
  903. "cpu %d %ld %ld %ld %ld %ld %ld %ld %ld %ld %ld ",
  904. cpu, stat->s_requestor, cycles_2_us(stat->s_time),
  905. stat->s_ntargself, stat->s_ntarglocals,
  906. stat->s_ntargremotes, stat->s_ntargcpu,
  907. stat->s_ntarglocaluvhub, stat->s_ntargremoteuvhub,
  908. stat->s_ntarguvhub, stat->s_ntarguvhub16);
  909. seq_printf(file, "%ld %ld %ld %ld %ld ",
  910. stat->s_ntarguvhub8, stat->s_ntarguvhub4,
  911. stat->s_ntarguvhub2, stat->s_ntarguvhub1,
  912. stat->s_dtimeout);
  913. seq_printf(file, "%ld %ld %ld %ld %ld %ld %ld %ld ",
  914. stat->s_retry_messages, stat->s_retriesok,
  915. stat->s_resets_plug, stat->s_resets_timeout,
  916. stat->s_giveup, stat->s_stimeout,
  917. stat->s_busy, stat->s_throttles);
  918. /* destination side statistics */
  919. seq_printf(file,
  920. "%lx %ld %ld %ld %ld %ld %ld %ld %ld %ld %ld %ld ",
  921. uv_read_global_mmr64(uv_cpu_to_pnode(cpu),
  922. UVH_LB_BAU_INTD_SOFTWARE_ACKNOWLEDGE),
  923. stat->d_requestee, cycles_2_us(stat->d_time),
  924. stat->d_alltlb, stat->d_onetlb, stat->d_multmsg,
  925. stat->d_nomsg, stat->d_retries, stat->d_canceled,
  926. stat->d_nocanceled, stat->d_resets,
  927. stat->d_rcanceled);
  928. seq_printf(file, "%ld %ld\n",
  929. stat->s_bau_disabled, stat->s_bau_reenabled);
  930. }
  931. return 0;
  932. }
  933. /*
  934. * Display the tunables thru debugfs
  935. */
  936. static ssize_t tunables_read(struct file *file, char __user *userbuf,
  937. size_t count, loff_t *ppos)
  938. {
  939. char *buf;
  940. int ret;
  941. buf = kasprintf(GFP_KERNEL, "%s %s %s\n%d %d %d %d %d %d %d %d %d\n",
  942. "max_bau_concurrent plugged_delay plugsb4reset",
  943. "timeoutsb4reset ipi_reset_limit complete_threshold",
  944. "congested_response_us congested_reps congested_period",
  945. max_bau_concurrent, plugged_delay, plugsb4reset,
  946. timeoutsb4reset, ipi_reset_limit, complete_threshold,
  947. congested_response_us, congested_reps, congested_period);
  948. if (!buf)
  949. return -ENOMEM;
  950. ret = simple_read_from_buffer(userbuf, count, ppos, buf, strlen(buf));
  951. kfree(buf);
  952. return ret;
  953. }
  954. /*
  955. * -1: resetf the statistics
  956. * 0: display meaning of the statistics
  957. */
  958. static ssize_t uv_ptc_proc_write(struct file *file, const char __user *user,
  959. size_t count, loff_t *data)
  960. {
  961. int cpu;
  962. long input_arg;
  963. char optstr[64];
  964. struct ptc_stats *stat;
  965. if (count == 0 || count > sizeof(optstr))
  966. return -EINVAL;
  967. if (copy_from_user(optstr, user, count))
  968. return -EFAULT;
  969. optstr[count - 1] = '\0';
  970. if (strict_strtol(optstr, 10, &input_arg) < 0) {
  971. printk(KERN_DEBUG "%s is invalid\n", optstr);
  972. return -EINVAL;
  973. }
  974. if (input_arg == 0) {
  975. printk(KERN_DEBUG "# cpu: cpu number\n");
  976. printk(KERN_DEBUG "Sender statistics:\n");
  977. printk(KERN_DEBUG
  978. "sent: number of shootdown messages sent\n");
  979. printk(KERN_DEBUG
  980. "stime: time spent sending messages\n");
  981. printk(KERN_DEBUG
  982. "numuvhubs: number of hubs targeted with shootdown\n");
  983. printk(KERN_DEBUG
  984. "numuvhubs16: number times 16 or more hubs targeted\n");
  985. printk(KERN_DEBUG
  986. "numuvhubs8: number times 8 or more hubs targeted\n");
  987. printk(KERN_DEBUG
  988. "numuvhubs4: number times 4 or more hubs targeted\n");
  989. printk(KERN_DEBUG
  990. "numuvhubs2: number times 2 or more hubs targeted\n");
  991. printk(KERN_DEBUG
  992. "numuvhubs1: number times 1 hub targeted\n");
  993. printk(KERN_DEBUG
  994. "numcpus: number of cpus targeted with shootdown\n");
  995. printk(KERN_DEBUG
  996. "dto: number of destination timeouts\n");
  997. printk(KERN_DEBUG
  998. "retries: destination timeout retries sent\n");
  999. printk(KERN_DEBUG
  1000. "rok: : destination timeouts successfully retried\n");
  1001. printk(KERN_DEBUG
  1002. "resetp: ipi-style resource resets for plugs\n");
  1003. printk(KERN_DEBUG
  1004. "resett: ipi-style resource resets for timeouts\n");
  1005. printk(KERN_DEBUG
  1006. "giveup: fall-backs to ipi-style shootdowns\n");
  1007. printk(KERN_DEBUG
  1008. "sto: number of source timeouts\n");
  1009. printk(KERN_DEBUG
  1010. "bz: number of stay-busy's\n");
  1011. printk(KERN_DEBUG
  1012. "throt: number times spun in throttle\n");
  1013. printk(KERN_DEBUG "Destination side statistics:\n");
  1014. printk(KERN_DEBUG
  1015. "sw_ack: image of UVH_LB_BAU_INTD_SOFTWARE_ACKNOWLEDGE\n");
  1016. printk(KERN_DEBUG
  1017. "recv: shootdown messages received\n");
  1018. printk(KERN_DEBUG
  1019. "rtime: time spent processing messages\n");
  1020. printk(KERN_DEBUG
  1021. "all: shootdown all-tlb messages\n");
  1022. printk(KERN_DEBUG
  1023. "one: shootdown one-tlb messages\n");
  1024. printk(KERN_DEBUG
  1025. "mult: interrupts that found multiple messages\n");
  1026. printk(KERN_DEBUG
  1027. "none: interrupts that found no messages\n");
  1028. printk(KERN_DEBUG
  1029. "retry: number of retry messages processed\n");
  1030. printk(KERN_DEBUG
  1031. "canc: number messages canceled by retries\n");
  1032. printk(KERN_DEBUG
  1033. "nocan: number retries that found nothing to cancel\n");
  1034. printk(KERN_DEBUG
  1035. "reset: number of ipi-style reset requests processed\n");
  1036. printk(KERN_DEBUG
  1037. "rcan: number messages canceled by reset requests\n");
  1038. printk(KERN_DEBUG
  1039. "disable: number times use of the BAU was disabled\n");
  1040. printk(KERN_DEBUG
  1041. "enable: number times use of the BAU was re-enabled\n");
  1042. } else if (input_arg == -1) {
  1043. for_each_present_cpu(cpu) {
  1044. stat = &per_cpu(ptcstats, cpu);
  1045. memset(stat, 0, sizeof(struct ptc_stats));
  1046. }
  1047. }
  1048. return count;
  1049. }
  1050. static int local_atoi(const char *name)
  1051. {
  1052. int val = 0;
  1053. for (;; name++) {
  1054. switch (*name) {
  1055. case '0' ... '9':
  1056. val = 10*val+(*name-'0');
  1057. break;
  1058. default:
  1059. return val;
  1060. }
  1061. }
  1062. }
  1063. /*
  1064. * set the tunables
  1065. * 0 values reset them to defaults
  1066. */
  1067. static ssize_t tunables_write(struct file *file, const char __user *user,
  1068. size_t count, loff_t *data)
  1069. {
  1070. int cpu;
  1071. int cnt = 0;
  1072. int val;
  1073. char *p;
  1074. char *q;
  1075. char instr[64];
  1076. struct bau_control *bcp;
  1077. if (count == 0 || count > sizeof(instr)-1)
  1078. return -EINVAL;
  1079. if (copy_from_user(instr, user, count))
  1080. return -EFAULT;
  1081. instr[count] = '\0';
  1082. /* count the fields */
  1083. p = instr + strspn(instr, WHITESPACE);
  1084. q = p;
  1085. for (; *p; p = q + strspn(q, WHITESPACE)) {
  1086. q = p + strcspn(p, WHITESPACE);
  1087. cnt++;
  1088. if (q == p)
  1089. break;
  1090. }
  1091. if (cnt != 9) {
  1092. printk(KERN_INFO "bau tunable error: should be 9 numbers\n");
  1093. return -EINVAL;
  1094. }
  1095. p = instr + strspn(instr, WHITESPACE);
  1096. q = p;
  1097. for (cnt = 0; *p; p = q + strspn(q, WHITESPACE), cnt++) {
  1098. q = p + strcspn(p, WHITESPACE);
  1099. val = local_atoi(p);
  1100. switch (cnt) {
  1101. case 0:
  1102. if (val == 0) {
  1103. max_bau_concurrent = MAX_BAU_CONCURRENT;
  1104. max_bau_concurrent_constant =
  1105. MAX_BAU_CONCURRENT;
  1106. continue;
  1107. }
  1108. bcp = &per_cpu(bau_control, smp_processor_id());
  1109. if (val < 1 || val > bcp->cpus_in_uvhub) {
  1110. printk(KERN_DEBUG
  1111. "Error: BAU max concurrent %d is invalid\n",
  1112. val);
  1113. return -EINVAL;
  1114. }
  1115. max_bau_concurrent = val;
  1116. max_bau_concurrent_constant = val;
  1117. continue;
  1118. case 1:
  1119. if (val == 0)
  1120. plugged_delay = PLUGGED_DELAY;
  1121. else
  1122. plugged_delay = val;
  1123. continue;
  1124. case 2:
  1125. if (val == 0)
  1126. plugsb4reset = PLUGSB4RESET;
  1127. else
  1128. plugsb4reset = val;
  1129. continue;
  1130. case 3:
  1131. if (val == 0)
  1132. timeoutsb4reset = TIMEOUTSB4RESET;
  1133. else
  1134. timeoutsb4reset = val;
  1135. continue;
  1136. case 4:
  1137. if (val == 0)
  1138. ipi_reset_limit = IPI_RESET_LIMIT;
  1139. else
  1140. ipi_reset_limit = val;
  1141. continue;
  1142. case 5:
  1143. if (val == 0)
  1144. complete_threshold = COMPLETE_THRESHOLD;
  1145. else
  1146. complete_threshold = val;
  1147. continue;
  1148. case 6:
  1149. if (val == 0)
  1150. congested_response_us = CONGESTED_RESPONSE_US;
  1151. else
  1152. congested_response_us = val;
  1153. continue;
  1154. case 7:
  1155. if (val == 0)
  1156. congested_reps = CONGESTED_REPS;
  1157. else
  1158. congested_reps = val;
  1159. continue;
  1160. case 8:
  1161. if (val == 0)
  1162. congested_period = CONGESTED_PERIOD;
  1163. else
  1164. congested_period = val;
  1165. continue;
  1166. }
  1167. if (q == p)
  1168. break;
  1169. }
  1170. for_each_present_cpu(cpu) {
  1171. bcp = &per_cpu(bau_control, cpu);
  1172. bcp->max_bau_concurrent = max_bau_concurrent;
  1173. bcp->max_bau_concurrent_constant = max_bau_concurrent;
  1174. bcp->plugged_delay = plugged_delay;
  1175. bcp->plugsb4reset = plugsb4reset;
  1176. bcp->timeoutsb4reset = timeoutsb4reset;
  1177. bcp->ipi_reset_limit = ipi_reset_limit;
  1178. bcp->complete_threshold = complete_threshold;
  1179. bcp->congested_response_us = congested_response_us;
  1180. bcp->congested_reps = congested_reps;
  1181. bcp->congested_period = congested_period;
  1182. }
  1183. return count;
  1184. }
  1185. static const struct seq_operations uv_ptc_seq_ops = {
  1186. .start = uv_ptc_seq_start,
  1187. .next = uv_ptc_seq_next,
  1188. .stop = uv_ptc_seq_stop,
  1189. .show = uv_ptc_seq_show
  1190. };
  1191. static int uv_ptc_proc_open(struct inode *inode, struct file *file)
  1192. {
  1193. return seq_open(file, &uv_ptc_seq_ops);
  1194. }
  1195. static int tunables_open(struct inode *inode, struct file *file)
  1196. {
  1197. return 0;
  1198. }
  1199. static const struct file_operations proc_uv_ptc_operations = {
  1200. .open = uv_ptc_proc_open,
  1201. .read = seq_read,
  1202. .write = uv_ptc_proc_write,
  1203. .llseek = seq_lseek,
  1204. .release = seq_release,
  1205. };
  1206. static const struct file_operations tunables_fops = {
  1207. .open = tunables_open,
  1208. .read = tunables_read,
  1209. .write = tunables_write,
  1210. .llseek = default_llseek,
  1211. };
  1212. static int __init uv_ptc_init(void)
  1213. {
  1214. struct proc_dir_entry *proc_uv_ptc;
  1215. if (!is_uv_system())
  1216. return 0;
  1217. proc_uv_ptc = proc_create(UV_PTC_BASENAME, 0444, NULL,
  1218. &proc_uv_ptc_operations);
  1219. if (!proc_uv_ptc) {
  1220. printk(KERN_ERR "unable to create %s proc entry\n",
  1221. UV_PTC_BASENAME);
  1222. return -EINVAL;
  1223. }
  1224. tunables_dir = debugfs_create_dir(UV_BAU_TUNABLES_DIR, NULL);
  1225. if (!tunables_dir) {
  1226. printk(KERN_ERR "unable to create debugfs directory %s\n",
  1227. UV_BAU_TUNABLES_DIR);
  1228. return -EINVAL;
  1229. }
  1230. tunables_file = debugfs_create_file(UV_BAU_TUNABLES_FILE, 0600,
  1231. tunables_dir, NULL, &tunables_fops);
  1232. if (!tunables_file) {
  1233. printk(KERN_ERR "unable to create debugfs file %s\n",
  1234. UV_BAU_TUNABLES_FILE);
  1235. return -EINVAL;
  1236. }
  1237. return 0;
  1238. }
  1239. /*
  1240. * Initialize the sending side's sending buffers.
  1241. */
  1242. static void
  1243. uv_activation_descriptor_init(int node, int pnode, int base_pnode)
  1244. {
  1245. int i;
  1246. int cpu;
  1247. unsigned long pa;
  1248. unsigned long m;
  1249. unsigned long n;
  1250. struct bau_desc *bau_desc;
  1251. struct bau_desc *bd2;
  1252. struct bau_control *bcp;
  1253. /*
  1254. * each bau_desc is 64 bytes; there are 8 (UV_ITEMS_PER_DESCRIPTOR)
  1255. * per cpu; and one per cpu on the uvhub (UV_ADP_SIZE)
  1256. */
  1257. bau_desc = kmalloc_node(sizeof(struct bau_desc) * UV_ADP_SIZE
  1258. * UV_ITEMS_PER_DESCRIPTOR, GFP_KERNEL, node);
  1259. BUG_ON(!bau_desc);
  1260. pa = uv_gpa(bau_desc); /* need the real nasid*/
  1261. n = pa >> uv_nshift;
  1262. m = pa & uv_mmask;
  1263. /* the 14-bit pnode */
  1264. uv_write_global_mmr64(pnode, UVH_LB_BAU_SB_DESCRIPTOR_BASE,
  1265. (n << UV_DESC_BASE_PNODE_SHIFT | m));
  1266. /*
  1267. * Initializing all 8 (UV_ITEMS_PER_DESCRIPTOR) descriptors for each
  1268. * cpu even though we only use the first one; one descriptor can
  1269. * describe a broadcast to 256 uv hubs.
  1270. */
  1271. for (i = 0, bd2 = bau_desc; i < (UV_ADP_SIZE*UV_ITEMS_PER_DESCRIPTOR);
  1272. i++, bd2++) {
  1273. memset(bd2, 0, sizeof(struct bau_desc));
  1274. bd2->header.sw_ack_flag = 1;
  1275. /*
  1276. * The base_dest_nasid set in the message header is the nasid
  1277. * of the first uvhub in the partition. The bit map will
  1278. * indicate destination pnode numbers relative to that base.
  1279. * They may not be consecutive if nasid striding is being used.
  1280. */
  1281. bd2->header.base_dest_nasid = UV_PNODE_TO_NASID(base_pnode);
  1282. bd2->header.dest_subnodeid = UV_LB_SUBNODEID;
  1283. bd2->header.command = UV_NET_ENDPOINT_INTD;
  1284. bd2->header.int_both = 1;
  1285. /*
  1286. * all others need to be set to zero:
  1287. * fairness chaining multilevel count replied_to
  1288. */
  1289. }
  1290. for_each_present_cpu(cpu) {
  1291. if (pnode != uv_blade_to_pnode(uv_cpu_to_blade_id(cpu)))
  1292. continue;
  1293. bcp = &per_cpu(bau_control, cpu);
  1294. bcp->descriptor_base = bau_desc;
  1295. }
  1296. }
  1297. /*
  1298. * initialize the destination side's receiving buffers
  1299. * entered for each uvhub in the partition
  1300. * - node is first node (kernel memory notion) on the uvhub
  1301. * - pnode is the uvhub's physical identifier
  1302. */
  1303. static void
  1304. uv_payload_queue_init(int node, int pnode)
  1305. {
  1306. int pn;
  1307. int cpu;
  1308. char *cp;
  1309. unsigned long pa;
  1310. struct bau_payload_queue_entry *pqp;
  1311. struct bau_payload_queue_entry *pqp_malloc;
  1312. struct bau_control *bcp;
  1313. pqp = kmalloc_node((DEST_Q_SIZE + 1)
  1314. * sizeof(struct bau_payload_queue_entry),
  1315. GFP_KERNEL, node);
  1316. BUG_ON(!pqp);
  1317. pqp_malloc = pqp;
  1318. cp = (char *)pqp + 31;
  1319. pqp = (struct bau_payload_queue_entry *)(((unsigned long)cp >> 5) << 5);
  1320. for_each_present_cpu(cpu) {
  1321. if (pnode != uv_cpu_to_pnode(cpu))
  1322. continue;
  1323. /* for every cpu on this pnode: */
  1324. bcp = &per_cpu(bau_control, cpu);
  1325. bcp->va_queue_first = pqp;
  1326. bcp->bau_msg_head = pqp;
  1327. bcp->va_queue_last = pqp + (DEST_Q_SIZE - 1);
  1328. }
  1329. /*
  1330. * need the pnode of where the memory was really allocated
  1331. */
  1332. pa = uv_gpa(pqp);
  1333. pn = pa >> uv_nshift;
  1334. uv_write_global_mmr64(pnode,
  1335. UVH_LB_BAU_INTD_PAYLOAD_QUEUE_FIRST,
  1336. ((unsigned long)pn << UV_PAYLOADQ_PNODE_SHIFT) |
  1337. uv_physnodeaddr(pqp));
  1338. uv_write_global_mmr64(pnode, UVH_LB_BAU_INTD_PAYLOAD_QUEUE_TAIL,
  1339. uv_physnodeaddr(pqp));
  1340. uv_write_global_mmr64(pnode, UVH_LB_BAU_INTD_PAYLOAD_QUEUE_LAST,
  1341. (unsigned long)
  1342. uv_physnodeaddr(pqp + (DEST_Q_SIZE - 1)));
  1343. /* in effect, all msg_type's are set to MSG_NOOP */
  1344. memset(pqp, 0, sizeof(struct bau_payload_queue_entry) * DEST_Q_SIZE);
  1345. }
  1346. /*
  1347. * Initialization of each UV hub's structures
  1348. */
  1349. static void __init uv_init_uvhub(int uvhub, int vector, int base_pnode)
  1350. {
  1351. int node;
  1352. int pnode;
  1353. unsigned long apicid;
  1354. node = uvhub_to_first_node(uvhub);
  1355. pnode = uv_blade_to_pnode(uvhub);
  1356. uv_activation_descriptor_init(node, pnode, base_pnode);
  1357. uv_payload_queue_init(node, pnode);
  1358. /*
  1359. * The below initialization can't be in firmware because the
  1360. * messaging IRQ will be determined by the OS.
  1361. */
  1362. apicid = uvhub_to_first_apicid(uvhub) | uv_apicid_hibits;
  1363. uv_write_global_mmr64(pnode, UVH_BAU_DATA_CONFIG,
  1364. ((apicid << 32) | vector));
  1365. }
  1366. /*
  1367. * We will set BAU_MISC_CONTROL with a timeout period.
  1368. * But the BIOS has set UVH_AGING_PRESCALE_SEL and UVH_TRANSACTION_TIMEOUT.
  1369. * So the destination timeout period has be be calculated from them.
  1370. */
  1371. static int
  1372. calculate_destination_timeout(void)
  1373. {
  1374. unsigned long mmr_image;
  1375. int mult1;
  1376. int mult2;
  1377. int index;
  1378. int base;
  1379. int ret;
  1380. unsigned long ts_ns;
  1381. mult1 = UV_INTD_SOFT_ACK_TIMEOUT_PERIOD & BAU_MISC_CONTROL_MULT_MASK;
  1382. mmr_image = uv_read_local_mmr(UVH_AGING_PRESCALE_SEL);
  1383. index = (mmr_image >> BAU_URGENCY_7_SHIFT) & BAU_URGENCY_7_MASK;
  1384. mmr_image = uv_read_local_mmr(UVH_TRANSACTION_TIMEOUT);
  1385. mult2 = (mmr_image >> BAU_TRANS_SHIFT) & BAU_TRANS_MASK;
  1386. base = timeout_base_ns[index];
  1387. ts_ns = base * mult1 * mult2;
  1388. ret = ts_ns / 1000;
  1389. return ret;
  1390. }
  1391. /*
  1392. * initialize the bau_control structure for each cpu
  1393. */
  1394. static int __init uv_init_per_cpu(int nuvhubs, int base_part_pnode)
  1395. {
  1396. int i;
  1397. int cpu;
  1398. int tcpu;
  1399. int pnode;
  1400. int uvhub;
  1401. int have_hmaster;
  1402. short socket = 0;
  1403. unsigned short socket_mask;
  1404. unsigned char *uvhub_mask;
  1405. struct bau_control *bcp;
  1406. struct uvhub_desc *bdp;
  1407. struct socket_desc *sdp;
  1408. struct bau_control *hmaster = NULL;
  1409. struct bau_control *smaster = NULL;
  1410. struct socket_desc {
  1411. short num_cpus;
  1412. short cpu_number[MAX_CPUS_PER_SOCKET];
  1413. };
  1414. struct uvhub_desc {
  1415. unsigned short socket_mask;
  1416. short num_cpus;
  1417. short uvhub;
  1418. short pnode;
  1419. struct socket_desc socket[2];
  1420. };
  1421. struct uvhub_desc *uvhub_descs;
  1422. timeout_us = calculate_destination_timeout();
  1423. uvhub_descs = kmalloc(nuvhubs * sizeof(struct uvhub_desc), GFP_KERNEL);
  1424. memset(uvhub_descs, 0, nuvhubs * sizeof(struct uvhub_desc));
  1425. uvhub_mask = kzalloc((nuvhubs+7)/8, GFP_KERNEL);
  1426. for_each_present_cpu(cpu) {
  1427. bcp = &per_cpu(bau_control, cpu);
  1428. memset(bcp, 0, sizeof(struct bau_control));
  1429. pnode = uv_cpu_hub_info(cpu)->pnode;
  1430. if ((pnode - base_part_pnode) >= UV_DISTRIBUTION_SIZE) {
  1431. printk(KERN_EMERG
  1432. "cpu %d pnode %d-%d beyond %d; BAU disabled\n",
  1433. cpu, pnode, base_part_pnode,
  1434. UV_DISTRIBUTION_SIZE);
  1435. return 1;
  1436. }
  1437. bcp->osnode = cpu_to_node(cpu);
  1438. bcp->partition_base_pnode = uv_partition_base_pnode;
  1439. uvhub = uv_cpu_hub_info(cpu)->numa_blade_id;
  1440. *(uvhub_mask + (uvhub/8)) |= (1 << (uvhub%8));
  1441. bdp = &uvhub_descs[uvhub];
  1442. bdp->num_cpus++;
  1443. bdp->uvhub = uvhub;
  1444. bdp->pnode = pnode;
  1445. /* kludge: 'assuming' one node per socket, and assuming that
  1446. disabling a socket just leaves a gap in node numbers */
  1447. socket = bcp->osnode & 1;
  1448. bdp->socket_mask |= (1 << socket);
  1449. sdp = &bdp->socket[socket];
  1450. sdp->cpu_number[sdp->num_cpus] = cpu;
  1451. sdp->num_cpus++;
  1452. if (sdp->num_cpus > MAX_CPUS_PER_SOCKET) {
  1453. printk(KERN_EMERG "%d cpus per socket invalid\n", sdp->num_cpus);
  1454. return 1;
  1455. }
  1456. }
  1457. for (uvhub = 0; uvhub < nuvhubs; uvhub++) {
  1458. if (!(*(uvhub_mask + (uvhub/8)) & (1 << (uvhub%8))))
  1459. continue;
  1460. have_hmaster = 0;
  1461. bdp = &uvhub_descs[uvhub];
  1462. socket_mask = bdp->socket_mask;
  1463. socket = 0;
  1464. while (socket_mask) {
  1465. if (!(socket_mask & 1))
  1466. goto nextsocket;
  1467. sdp = &bdp->socket[socket];
  1468. for (i = 0; i < sdp->num_cpus; i++) {
  1469. cpu = sdp->cpu_number[i];
  1470. bcp = &per_cpu(bau_control, cpu);
  1471. bcp->cpu = cpu;
  1472. if (i == 0) {
  1473. smaster = bcp;
  1474. if (!have_hmaster) {
  1475. have_hmaster++;
  1476. hmaster = bcp;
  1477. }
  1478. }
  1479. bcp->cpus_in_uvhub = bdp->num_cpus;
  1480. bcp->cpus_in_socket = sdp->num_cpus;
  1481. bcp->socket_master = smaster;
  1482. bcp->uvhub = bdp->uvhub;
  1483. bcp->uvhub_master = hmaster;
  1484. bcp->uvhub_cpu = uv_cpu_hub_info(cpu)->
  1485. blade_processor_id;
  1486. if (bcp->uvhub_cpu >= MAX_CPUS_PER_UVHUB) {
  1487. printk(KERN_EMERG
  1488. "%d cpus per uvhub invalid\n",
  1489. bcp->uvhub_cpu);
  1490. return 1;
  1491. }
  1492. }
  1493. nextsocket:
  1494. socket++;
  1495. socket_mask = (socket_mask >> 1);
  1496. /* each socket gets a local array of pnodes/hubs */
  1497. bcp = smaster;
  1498. bcp->target_hub_and_pnode = kmalloc_node(
  1499. sizeof(struct hub_and_pnode) *
  1500. num_possible_cpus(), GFP_KERNEL, bcp->osnode);
  1501. memset(bcp->target_hub_and_pnode, 0,
  1502. sizeof(struct hub_and_pnode) *
  1503. num_possible_cpus());
  1504. for_each_present_cpu(tcpu) {
  1505. bcp->target_hub_and_pnode[tcpu].pnode =
  1506. uv_cpu_hub_info(tcpu)->pnode;
  1507. bcp->target_hub_and_pnode[tcpu].uvhub =
  1508. uv_cpu_hub_info(tcpu)->numa_blade_id;
  1509. }
  1510. }
  1511. }
  1512. kfree(uvhub_descs);
  1513. kfree(uvhub_mask);
  1514. for_each_present_cpu(cpu) {
  1515. bcp = &per_cpu(bau_control, cpu);
  1516. bcp->baudisabled = 0;
  1517. bcp->statp = &per_cpu(ptcstats, cpu);
  1518. /* time interval to catch a hardware stay-busy bug */
  1519. bcp->timeout_interval = microsec_2_cycles(2*timeout_us);
  1520. bcp->max_bau_concurrent = max_bau_concurrent;
  1521. bcp->max_bau_concurrent_constant = max_bau_concurrent;
  1522. bcp->plugged_delay = plugged_delay;
  1523. bcp->plugsb4reset = plugsb4reset;
  1524. bcp->timeoutsb4reset = timeoutsb4reset;
  1525. bcp->ipi_reset_limit = ipi_reset_limit;
  1526. bcp->complete_threshold = complete_threshold;
  1527. bcp->congested_response_us = congested_response_us;
  1528. bcp->congested_reps = congested_reps;
  1529. bcp->congested_period = congested_period;
  1530. }
  1531. return 0;
  1532. }
  1533. /*
  1534. * Initialization of BAU-related structures
  1535. */
  1536. static int __init uv_bau_init(void)
  1537. {
  1538. int uvhub;
  1539. int pnode;
  1540. int nuvhubs;
  1541. int cur_cpu;
  1542. int vector;
  1543. unsigned long mmr;
  1544. if (!is_uv_system())
  1545. return 0;
  1546. if (nobau)
  1547. return 0;
  1548. for_each_possible_cpu(cur_cpu)
  1549. zalloc_cpumask_var_node(&per_cpu(uv_flush_tlb_mask, cur_cpu),
  1550. GFP_KERNEL, cpu_to_node(cur_cpu));
  1551. uv_nshift = uv_hub_info->m_val;
  1552. uv_mmask = (1UL << uv_hub_info->m_val) - 1;
  1553. nuvhubs = uv_num_possible_blades();
  1554. spin_lock_init(&disable_lock);
  1555. congested_cycles = microsec_2_cycles(congested_response_us);
  1556. uv_partition_base_pnode = 0x7fffffff;
  1557. for (uvhub = 0; uvhub < nuvhubs; uvhub++) {
  1558. if (uv_blade_nr_possible_cpus(uvhub) &&
  1559. (uv_blade_to_pnode(uvhub) < uv_partition_base_pnode))
  1560. uv_partition_base_pnode = uv_blade_to_pnode(uvhub);
  1561. }
  1562. if (uv_init_per_cpu(nuvhubs, uv_partition_base_pnode)) {
  1563. nobau = 1;
  1564. return 0;
  1565. }
  1566. vector = UV_BAU_MESSAGE;
  1567. for_each_possible_blade(uvhub)
  1568. if (uv_blade_nr_possible_cpus(uvhub))
  1569. uv_init_uvhub(uvhub, vector, uv_partition_base_pnode);
  1570. uv_enable_timeouts();
  1571. alloc_intr_gate(vector, uv_bau_message_intr1);
  1572. for_each_possible_blade(uvhub) {
  1573. if (uv_blade_nr_possible_cpus(uvhub)) {
  1574. pnode = uv_blade_to_pnode(uvhub);
  1575. /* INIT the bau */
  1576. uv_write_global_mmr64(pnode,
  1577. UVH_LB_BAU_SB_ACTIVATION_CONTROL,
  1578. ((unsigned long)1 << 63));
  1579. mmr = 1; /* should be 1 to broadcast to both sockets */
  1580. uv_write_global_mmr64(pnode, UVH_BAU_DATA_BROADCAST,
  1581. mmr);
  1582. }
  1583. }
  1584. return 0;
  1585. }
  1586. core_initcall(uv_bau_init);
  1587. fs_initcall(uv_ptc_init);