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

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

Version: ~ [ linux-5.15-rc5 ] ~ [ linux-5.14.11 ] ~ [ linux-5.13.19 ] ~ [ linux-5.12.19 ] ~ [ linux-5.11.22 ] ~ [ linux-5.10.72 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.152 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.210 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.250 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.286 ] ~ [ linux-4.8.17 ] ~ [ linux-4.7.10 ] ~ [ linux-4.6.7 ] ~ [ linux-4.5.7 ] ~ [ linux-4.4.288 ] ~ [ linux-4.3.6 ] ~ [ linux-4.2.8 ] ~ [ linux-4.1.52 ] ~ [ linux-4.0.9 ] ~ [ linux-3.18.140 ] ~ [ linux-3.16.85 ] ~ [ linux-3.14.79 ] ~ [ linux-3.12.74 ] ~ [ 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.5 ] ~ [ 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/buffer_head.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 };
 25 
 26 void *squashfs_decompressor_create(struct squashfs_sb_info *msblk,
 27                                                 void *comp_opts)
 28 {
 29         struct squashfs_stream *stream;
 30         struct squashfs_stream __percpu *percpu;
 31         int err, cpu;
 32 
 33         percpu = alloc_percpu(struct squashfs_stream);
 34         if (percpu == NULL)
 35                 return ERR_PTR(-ENOMEM);
 36 
 37         for_each_possible_cpu(cpu) {
 38                 stream = per_cpu_ptr(percpu, cpu);
 39                 stream->stream = msblk->decompressor->init(msblk, comp_opts);
 40                 if (IS_ERR(stream->stream)) {
 41                         err = PTR_ERR(stream->stream);
 42                         goto out;
 43                 }
 44         }
 45 
 46         kfree(comp_opts);
 47         return (__force void *) percpu;
 48 
 49 out:
 50         for_each_possible_cpu(cpu) {
 51                 stream = per_cpu_ptr(percpu, cpu);
 52                 if (!IS_ERR_OR_NULL(stream->stream))
 53                         msblk->decompressor->free(stream->stream);
 54         }
 55         free_percpu(percpu);
 56         return ERR_PTR(err);
 57 }
 58 
 59 void squashfs_decompressor_destroy(struct squashfs_sb_info *msblk)
 60 {
 61         struct squashfs_stream __percpu *percpu =
 62                         (struct squashfs_stream __percpu *) msblk->stream;
 63         struct squashfs_stream *stream;
 64         int cpu;
 65 
 66         if (msblk->stream) {
 67                 for_each_possible_cpu(cpu) {
 68                         stream = per_cpu_ptr(percpu, cpu);
 69                         msblk->decompressor->free(stream->stream);
 70                 }
 71                 free_percpu(percpu);
 72         }
 73 }
 74 
 75 int squashfs_decompress(struct squashfs_sb_info *msblk, struct buffer_head **bh,
 76         int b, int offset, int length, struct squashfs_page_actor *output)
 77 {
 78         struct squashfs_stream __percpu *percpu =
 79                         (struct squashfs_stream __percpu *) msblk->stream;
 80         struct squashfs_stream *stream = get_cpu_ptr(percpu);
 81         int res = msblk->decompressor->decompress(msblk, stream->stream, bh, b,
 82                 offset, length, output);
 83         put_cpu_ptr(stream);
 84 
 85         if (res < 0)
 86                 ERROR("%s decompression failed, data probably corrupt\n",
 87                         msblk->decompressor->name);
 88 
 89         return res;
 90 }
 91 
 92 int squashfs_max_decompressors(void)
 93 {
 94         return num_possible_cpus();
 95 }
 96 

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

kernel.org | git.kernel.org | LWN.net | Project Home | Wiki (Japanese) | Wiki (English) | 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.

osdn.jp