Move fuse thread args out of fuse session object

This commit is contained in:
Antonio SJ Musumeci 2023-07-30 16:26:33 -05:00
parent 539f2221a3
commit 51d97bb444
7 changed files with 151 additions and 89 deletions

View File

@ -44,7 +44,6 @@ SRC_C = \
lib/fuse.c \
lib/fuse_dirents.c \
lib/fuse_lowlevel.c \
lib/fuse_mt.c \
lib/node.c \
lib/fuse_node.c \
lib/fuse_opt.c \
@ -57,7 +56,8 @@ SRC_CPP = \
lib/format.cpp \
lib/os.cpp \
lib/cpu.cpp \
lib/fuse_loop_mt.cpp \
lib/fuse_config.cpp \
lib/fuse_loop.cpp \
lib/fuse_msgbuf.cpp
OBJS_C = $(SRC_C:lib/%.c=build/%.o)
OBJS_CPP = $(SRC_CPP:lib/%.cpp=build/%.o)

View File

@ -0,0 +1,31 @@
/*
ISC License
Copyright (c) 2023, Antonio SJ Musumeci <trapexit@spawn.link>
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted, provided that the above
copyright notice and this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
#pragma once
#include <string>
int fuse_config_get_read_thread_count();
int fuse_config_get_process_thread_count();
int fuse_config_get_process_thread_queue_depth();
std::string fuse_config_get_pin_threads();
void fuse_config_set_read_thread_count(int const);
void fuse_config_set_process_thread_count(int const);
void fuse_config_set_process_thread_queue_depth(int const);
void fuse_config_set_pin_threads(std::string const);

View File

@ -72,10 +72,6 @@ struct fuse_config
int set_uid;
int set_gid;
int help;
int read_thread_count;
int process_thread_count;
int process_thread_queue_depth;
char *pin_threads;
};
struct fuse_fs
@ -3601,11 +3597,6 @@ static const struct fuse_opt fuse_lib_opts[] =
FUSE_LIB_OPT("gid=%d", gid,0),
FUSE_LIB_OPT("noforget", remember,-1),
FUSE_LIB_OPT("remember=%u", remember,0),
FUSE_LIB_OPT("threads=%d", read_thread_count,0),
FUSE_LIB_OPT("read-thread-count=%d", read_thread_count,0),
FUSE_LIB_OPT("process-thread-count=%d", process_thread_count,-1),
FUSE_LIB_OPT("process-thread-queue-depth=%d", process_thread_queue_depth,-1),
FUSE_LIB_OPT("pin-threads=%s", pin_threads, 0),
FUSE_OPT_END
};
@ -4044,31 +4035,6 @@ fuse_destroy(struct fuse *f)
fuse_delete_context_key();
}
int
fuse_config_read_thread_count(const struct fuse *f_)
{
return f_->conf.read_thread_count;
}
int
fuse_config_process_thread_count(const struct fuse *f_)
{
return f_->conf.process_thread_count;
}
int
fuse_config_process_thread_queue_depth(const struct fuse *f_)
{
return f_->conf.process_thread_queue_depth;
}
const
char*
fuse_config_pin_threads(const struct fuse *f_)
{
return f_->conf.pin_threads;
}
void
fuse_log_metrics_set(int log_)
{

View File

@ -0,0 +1,73 @@
/*
ISC License
Copyright (c) 2023, Antonio SJ Musumeci <trapexit@spawn.link>
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted, provided that the above
copyright notice and this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
#include <string>
static int g_READ_THREAD_COUNT = -1;
static int g_PROCESS_THREAD_COUNT = -1;
static int g_PROCESS_THREAD_QUEUE_DEPTH = -1;
static std::string g_PIN_THREADS = {};
int
fuse_config_get_read_thread_count()
{
return g_READ_THREAD_COUNT;
}
void
fuse_config_set_read_thread_count(int const v_)
{
g_READ_THREAD_COUNT = v_;
}
int
fuse_config_get_process_thread_count()
{
return g_PROCESS_THREAD_COUNT;
}
void
fuse_config_set_process_thread_count(int const v_)
{
g_PROCESS_THREAD_COUNT = v_;
}
int
fuse_config_get_process_thread_queue_depth()
{
return g_PROCESS_THREAD_QUEUE_DEPTH;
}
void
fuse_config_set_process_thread_queue_depth(int const v_)
{
g_PROCESS_THREAD_QUEUE_DEPTH = v_;
}
std::string
fuse_config_get_pin_threads()
{
return g_PIN_THREADS;
}
void
fuse_config_set_pin_threads(std::string const v_)
{
g_PIN_THREADS = v_;
}

View File

@ -13,6 +13,7 @@
#include "fuse_lowlevel.h"
#include "fuse_misc.h"
#include "fuse_config.hpp"
#include "fuse_msgbuf.hpp"
#include "fuse_ll.hpp"
@ -418,10 +419,12 @@ pin_threads_R1PPSP(const std::vector<pthread_t> read_threads_,
static
void
pin_threads(const std::vector<pthread_t> read_threads_,
const std::vector<pthread_t> process_threads_,
const std::string type_)
pin_threads(const std::vector<pthread_t> read_threads_,
const std::vector<pthread_t> process_threads_,
const std::string type_)
{
if(type_.empty())
return;
if(type_ == "R1L")
return ::pin_threads_R1L(read_threads_);
if(type_ == "R1P")
@ -440,6 +443,8 @@ pin_threads(const std::vector<pthread_t> read_threads_,
return ::pin_threads_RPSP(read_threads_,process_threads_);
if(type_ == "R1PPSP")
return ::pin_threads_R1PPSP(read_threads_,process_threads_);
syslog_warning("Invalid pin-threads value, ignoring: %s",type_.c_str());
}
static
@ -456,7 +461,7 @@ fuse_session_loop_mt(struct fuse_session *se_,
const int raw_read_thread_count_,
const int raw_process_thread_count_,
const int raw_process_thread_queue_depth_,
const char *pin_threads_type_)
const std::string pin_threads_type_)
{
sem_t finished;
int read_thread_count;
@ -496,13 +501,17 @@ fuse_session_loop_mt(struct fuse_session *se_,
if(process_tp)
process_threads = process_tp->threads();
if(pin_threads_type_ != nullptr)
::pin_threads(read_threads,process_threads,pin_threads_type_);
::pin_threads(read_threads,process_threads,pin_threads_type_);
syslog_info("read-thread-count=%d; process-thread-count=%d; process-thread-queue-depth=%d",
syslog_info("read-thread-count=%d; "
"process-thread-count=%d; "
"process-thread-queue-depth=%d; "
"pin-threads=%s;"
,
read_thread_count,
process_thread_count,
process_thread_queue_depth);
process_thread_queue_depth,
pin_threads_type_);
::wait(se_,&finished);
@ -510,3 +519,24 @@ fuse_session_loop_mt(struct fuse_session *se_,
return 0;
}
int
fuse_loop_mt(struct fuse *f)
{
if(f == NULL)
return -1;
int res = fuse_start_maintenance_thread(f);
if(res)
return -1;
res = fuse_session_loop_mt(fuse_get_session(f),
fuse_config_get_read_thread_count(),
fuse_config_get_process_thread_count(),
fuse_config_get_process_thread_queue_depth(),
fuse_config_get_pin_threads());
fuse_stop_maintenance_thread(f);
return res;
}

View File

@ -1,38 +0,0 @@
/*
FUSE: Filesystem in Userspace
Copyright (C) 2001-2007 Miklos Szeredi <miklos@szeredi.hu>
This program can be distributed under the terms of the GNU LGPLv2.
See the file COPYING.LIB.
*/
#include "fuse_i.h"
#include "fuse_misc.h"
#include "fuse_lowlevel.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <pthread.h>
#include <assert.h>
int
fuse_loop_mt(struct fuse *f)
{
if (f == NULL)
return -1;
int res = fuse_start_maintenance_thread(f);
if (res)
return -1;
res = fuse_session_loop_mt(fuse_get_session(f),
fuse_config_read_thread_count(f),
fuse_config_process_thread_count(f),
fuse_config_process_thread_queue_depth(f),
fuse_config_pin_threads(f));
fuse_stop_maintenance_thread(f);
return res;
}

View File

@ -29,6 +29,7 @@
#include "version.hpp"
#include "fuse.h"
#include "fuse_config.hpp"
#include <fstream>
#include <iomanip>
@ -77,13 +78,12 @@ set_kv_option(const std::string &key_,
static
void
set_fuse_threads(Config::Write &cfg_,
fuse_args *args_)
set_fuse_threads(Config::Write &cfg_)
{
set_kv_option("read-thread-count",cfg_->fuse_read_thread_count.to_string(),args_);
set_kv_option("process-thread-count",cfg_->fuse_process_thread_count.to_string(),args_);
set_kv_option("process-thread-queue-depth",cfg_->fuse_process_thread_queue_depth.to_string(),args_);
set_kv_option("pin-threads",cfg_->fuse_pin_threads.to_string(),args_);
fuse_config_set_read_thread_count(cfg_->fuse_read_thread_count);
fuse_config_set_process_thread_count(cfg_->fuse_process_thread_count);
fuse_config_set_process_thread_queue_depth(cfg_->fuse_process_thread_queue_depth);
fuse_config_set_pin_threads(cfg_->fuse_pin_threads);
}
static
@ -447,7 +447,7 @@ namespace options
set_default_options(args_);
set_fsname(cfg,args_);
set_subtype(args_);
set_fuse_threads(cfg,args_);
set_fuse_threads(cfg);
cfg->finish_initializing();
}