tlb_uv.c 46 KB

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