hc
2024-02-20 102a0743326a03cd1a1202ceda21e175b7d3575c
kernel/drivers/base/cacheinfo.c
....@@ -213,6 +213,8 @@
213213 return -ENOTSUPP;
214214 }
215215
216
+unsigned int coherency_max_size;
217
+
216218 static int cache_shared_cpu_map_setup(unsigned int cpu)
217219 {
218220 struct cpu_cacheinfo *this_cpu_ci = get_cpu_cacheinfo(cpu);
....@@ -251,6 +253,9 @@
251253 cpumask_set_cpu(i, &this_leaf->shared_cpu_map);
252254 }
253255 }
256
+ /* record the maximum cache line size */
257
+ if (this_leaf->coherency_line_size > coherency_max_size)
258
+ coherency_max_size = this_leaf->coherency_line_size;
254259 }
255260
256261 return 0;
....@@ -357,7 +362,7 @@
357362 struct device_attribute *attr, char *buf) \
358363 { \
359364 struct cacheinfo *this_leaf = dev_get_drvdata(dev); \
360
- return sprintf(buf, "%u\n", this_leaf->object); \
365
+ return sysfs_emit(buf, "%u\n", this_leaf->object); \
361366 }
362367
363368 show_one(id, id);
....@@ -372,44 +377,48 @@
372377 {
373378 struct cacheinfo *this_leaf = dev_get_drvdata(dev);
374379
375
- return sprintf(buf, "%uK\n", this_leaf->size >> 10);
376
-}
377
-
378
-static ssize_t shared_cpumap_show_func(struct device *dev, bool list, char *buf)
379
-{
380
- struct cacheinfo *this_leaf = dev_get_drvdata(dev);
381
- const struct cpumask *mask = &this_leaf->shared_cpu_map;
382
-
383
- return cpumap_print_to_pagebuf(list, buf, mask);
380
+ return sysfs_emit(buf, "%uK\n", this_leaf->size >> 10);
384381 }
385382
386383 static ssize_t shared_cpu_map_show(struct device *dev,
387384 struct device_attribute *attr, char *buf)
388385 {
389
- return shared_cpumap_show_func(dev, false, buf);
386
+ struct cacheinfo *this_leaf = dev_get_drvdata(dev);
387
+ const struct cpumask *mask = &this_leaf->shared_cpu_map;
388
+
389
+ return sysfs_emit(buf, "%*pb\n", nr_cpu_ids, mask);
390390 }
391391
392392 static ssize_t shared_cpu_list_show(struct device *dev,
393393 struct device_attribute *attr, char *buf)
394394 {
395
- return shared_cpumap_show_func(dev, true, buf);
395
+ struct cacheinfo *this_leaf = dev_get_drvdata(dev);
396
+ const struct cpumask *mask = &this_leaf->shared_cpu_map;
397
+
398
+ return sysfs_emit(buf, "%*pbl\n", nr_cpu_ids, mask);
396399 }
397400
398401 static ssize_t type_show(struct device *dev,
399402 struct device_attribute *attr, char *buf)
400403 {
401404 struct cacheinfo *this_leaf = dev_get_drvdata(dev);
405
+ const char *output;
402406
403407 switch (this_leaf->type) {
404408 case CACHE_TYPE_DATA:
405
- return sprintf(buf, "Data\n");
409
+ output = "Data";
410
+ break;
406411 case CACHE_TYPE_INST:
407
- return sprintf(buf, "Instruction\n");
412
+ output = "Instruction";
413
+ break;
408414 case CACHE_TYPE_UNIFIED:
409
- return sprintf(buf, "Unified\n");
415
+ output = "Unified";
416
+ break;
410417 default:
411418 return -EINVAL;
412419 }
420
+
421
+ return sysfs_emit(buf, "%s\n", output);
413422 }
414423
415424 static ssize_t allocation_policy_show(struct device *dev,
....@@ -417,15 +426,18 @@
417426 {
418427 struct cacheinfo *this_leaf = dev_get_drvdata(dev);
419428 unsigned int ci_attr = this_leaf->attributes;
420
- int n = 0;
429
+ const char *output;
421430
422431 if ((ci_attr & CACHE_READ_ALLOCATE) && (ci_attr & CACHE_WRITE_ALLOCATE))
423
- n = sprintf(buf, "ReadWriteAllocate\n");
432
+ output = "ReadWriteAllocate";
424433 else if (ci_attr & CACHE_READ_ALLOCATE)
425
- n = sprintf(buf, "ReadAllocate\n");
434
+ output = "ReadAllocate";
426435 else if (ci_attr & CACHE_WRITE_ALLOCATE)
427
- n = sprintf(buf, "WriteAllocate\n");
428
- return n;
436
+ output = "WriteAllocate";
437
+ else
438
+ return 0;
439
+
440
+ return sysfs_emit(buf, "%s\n", output);
429441 }
430442
431443 static ssize_t write_policy_show(struct device *dev,
....@@ -436,9 +448,9 @@
436448 int n = 0;
437449
438450 if (ci_attr & CACHE_WRITE_THROUGH)
439
- n = sprintf(buf, "WriteThrough\n");
451
+ n = sysfs_emit(buf, "WriteThrough\n");
440452 else if (ci_attr & CACHE_WRITE_BACK)
441
- n = sprintf(buf, "WriteBack\n");
453
+ n = sysfs_emit(buf, "WriteBack\n");
442454 return n;
443455 }
444456
....@@ -613,6 +625,8 @@
613625 this_leaf = this_cpu_ci->info_list + i;
614626 if (this_leaf->disable_sysfs)
615627 continue;
628
+ if (this_leaf->type == CACHE_TYPE_NOCACHE)
629
+ break;
616630 cache_groups = cache_get_attribute_groups(this_leaf);
617631 ci_dev = cpu_device_create(parent, this_leaf, cache_groups,
618632 "index%1u", i);