~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/fs/squashfs/decompressor_multi_percpu.c

Version: ~ [ linux-6.11-rc3 ] ~ [ linux-6.10.4 ] ~ [ linux-6.9.12 ] ~ [ linux-6.8.12 ] ~ [ linux-6.7.12 ] ~ [ linux-6.6.45 ] ~ [ linux-6.5.13 ] ~ [ linux-6.4.16 ] ~ [ linux-6.3.13 ] ~ [ linux-6.2.16 ] ~ [ linux-6.1.104 ] ~ [ linux-6.0.19 ] ~ [ linux-5.19.17 ] ~ [ linux-5.18.19 ] ~ [ linux-5.17.15 ] ~ [ linux-5.16.20 ] ~ [ linux-5.15.164 ] ~ [ linux-5.14.21 ] ~ [ linux-5.13.19 ] ~ [ linux-5.12.19 ] ~ [ linux-5.11.22 ] ~ [ linux-5.10.223 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.281 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.319 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.336 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.337 ] ~ [ linux-4.4.302 ] ~ [ linux-3.10.108 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.9 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  1 // SPDX-License-Identifier: GPL-2.0-only
  2 /*
  3  * Copyright (c) 2013
  4  * Phillip Lougher <phillip@squashfs.org.uk>
  5  */
  6 
  7 #include <linux/types.h>
  8 #include <linux/slab.h>
  9 #include <linux/percpu.h>
 10 #include <linux/local_lock.h>
 11 
 12 #include "squashfs_fs.h"
 13 #include "squashfs_fs_sb.h"
 14 #include "decompressor.h"
 15 #include "squashfs.h"
 16 
 17 /*
 18  * This file implements multi-threaded decompression using percpu
 19  * variables, one thread per cpu core.
 20  */
 21 
 22 struct squashfs_stream {
 23         void                    *stream;
 24         local_lock_t    lock;
 25 };
 26 
 27 static void *squashfs_decompressor_create(struct squashfs_sb_info *msblk,
 28                                                 void *comp_opts)
 29 {
 30         struct squashfs_stream *stream;
 31         struct squashfs_stream __percpu *percpu;
 32         int err, cpu;
 33 
 34         percpu = alloc_percpu(struct squashfs_stream);
 35         if (percpu == NULL)
 36                 return ERR_PTR(-ENOMEM);
 37 
 38         for_each_possible_cpu(cpu) {
 39                 stream = per_cpu_ptr(percpu, cpu);
 40                 stream->stream = msblk->decompressor->init(msblk, comp_opts);
 41                 if (IS_ERR(stream->stream)) {
 42                         err = PTR_ERR(stream->stream);
 43                         goto out;
 44                 }
 45                 local_lock_init(&stream->lock);
 46         }
 47 
 48         kfree(comp_opts);
 49         return (__force void *) percpu;
 50 
 51 out:
 52         for_each_possible_cpu(cpu) {
 53                 stream = per_cpu_ptr(percpu, cpu);
 54                 if (!IS_ERR_OR_NULL(stream->stream))
 55                         msblk->decompressor->free(stream->stream);
 56         }
 57         free_percpu(percpu);
 58         return ERR_PTR(err);
 59 }
 60 
 61 static void squashfs_decompressor_destroy(struct squashfs_sb_info *msblk)
 62 {
 63         struct squashfs_stream __percpu *percpu =
 64                         (struct squashfs_stream __percpu *) msblk->stream;
 65         struct squashfs_stream *stream;
 66         int cpu;
 67 
 68         if (msblk->stream) {
 69                 for_each_possible_cpu(cpu) {
 70                         stream = per_cpu_ptr(percpu, cpu);
 71                         msblk->decompressor->free(stream->stream);
 72                 }
 73                 free_percpu(percpu);
 74         }
 75 }
 76 
 77 static int squashfs_decompress(struct squashfs_sb_info *msblk, struct bio *bio,
 78         int offset, int length, struct squashfs_page_actor *output)
 79 {
 80         struct squashfs_stream *stream;
 81         struct squashfs_stream __percpu *percpu =
 82                         (struct squashfs_stream __percpu *) msblk->stream;
 83         int res;
 84 
 85         local_lock(&percpu->lock);
 86         stream = this_cpu_ptr(percpu);
 87 
 88         res = msblk->decompressor->decompress(msblk, stream->stream, bio,
 89                                               offset, length, output);
 90 
 91         local_unlock(&percpu->lock);
 92 
 93         if (res < 0)
 94                 ERROR("%s decompression failed, data probably corrupt\n",
 95                         msblk->decompressor->name);
 96 
 97         return res;
 98 }
 99 
100 static int squashfs_max_decompressors(void)
101 {
102         return num_possible_cpus();
103 }
104 
105 const struct squashfs_decompressor_thread_ops squashfs_decompressor_percpu = {
106         .create = squashfs_decompressor_create,
107         .destroy = squashfs_decompressor_destroy,
108         .decompress = squashfs_decompress,
109         .max_decompressors = squashfs_max_decompressors,
110 };
111 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

sflogo.php