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