Bug 1348591 - Support custom default segment buffer list size. r=billm

MozReview-Commit-ID: 2Nkj6RPx62f

--HG--
extra : rebase_source : 4e763563e3f9e9927314e804ba4e0fbd291fc9e8
This commit is contained in:
Henry Chang 2017-06-21 17:55:13 +08:00
parent 58682d9ad9
commit 6d648badcb
11 changed files with 93 additions and 14 deletions

View File

@ -126,8 +126,10 @@ void Pickle::UpdateIter(PickleIterator* iter, uint32_t bytes) const {
// Payload is sizeof(Pickle::memberAlignmentType) aligned.
Pickle::Pickle(uint32_t header_size)
: buffers_(AlignInt(header_size), kHeaderSegmentCapacity, kDefaultSegmentCapacity),
Pickle::Pickle(uint32_t header_size, size_t segment_capacity)
: buffers_(AlignInt(header_size),
segment_capacity ? segment_capacity : kHeaderSegmentCapacity,
segment_capacity ? segment_capacity : kDefaultSegmentCapacity),
header_(nullptr),
header_size_(AlignInt(header_size)) {
DCHECK(static_cast<memberAlignmentType>(header_size) >= sizeof(Header));

View File

@ -69,7 +69,7 @@ class Pickle {
// Initialize a Pickle object with the specified header size in bytes, which
// must be greater-than-or-equal-to sizeof(Pickle::Header). The header size
// will be rounded up to ensure that the header size is 32bit-aligned.
explicit Pickle(uint32_t header_size);
explicit Pickle(uint32_t header_size, size_t segment_capacity = 0);
Pickle(uint32_t header_size, const char* data, uint32_t length);

View File

@ -54,9 +54,15 @@ Message::Message()
InitLoggingVariables();
}
Message::Message(int32_t routing_id, msgid_t type, NestedLevel nestedLevel, PriorityValue priority,
MessageCompression compression, const char* const aName, bool recordWriteLatency)
: Pickle(MSG_HEADER_SZ) {
Message::Message(int32_t routing_id,
msgid_t type,
uint32_t segment_capacity,
NestedLevel nestedLevel,
PriorityValue priority,
MessageCompression compression,
const char* const aName,
bool recordWriteLatency)
: Pickle(MSG_HEADER_SZ, segment_capacity) {
MOZ_COUNT_CTOR(IPC::Message);
header()->routing = routing_id;
header()->type = type;

View File

@ -67,6 +67,7 @@ class Message : public Pickle {
// and is used to trigger the IPC_WRITE_LATENCY_MS telemetry.
Message(int32_t routing_id,
msgid_t type,
uint32_t segmentCapacity = 0, // 0 for the default capacity.
NestedLevel nestedLevel = NOT_NESTED,
PriorityValue priority = NORMAL_PRIORITY,
MessageCompression compression = COMPRESSION_NONE,

View File

@ -76,6 +76,7 @@ public:
NestedLevel aNestedLevel = NOT_NESTED)
: IPC::Message(MSG_ROUTING_CONTROL, // these only go to top-level actors
CHANNEL_OPENED_MESSAGE_TYPE,
0,
aNestedLevel)
{
IPC::WriteParam(this, aDescriptor);

View File

@ -25,7 +25,7 @@ public:
id_t aIPDLId,
size_t aSize,
SharedMemory::SharedMemoryType aType) :
IPC::Message(routingId, SHMEM_CREATED_MESSAGE_TYPE, NESTED_INSIDE_CPOW)
IPC::Message(routingId, SHMEM_CREATED_MESSAGE_TYPE, 0, NESTED_INSIDE_CPOW)
{
IPC::WriteParam(this, aIPDLId);
IPC::WriteParam(this, aSize);

View File

@ -20,6 +20,7 @@ ipdl: $(ALL_IPDLSRCS)
$(PLY_INCLUDE) \
$(srcdir)/ipdl.py \
--sync-msg-list=$(srcdir)/sync-messages.ini \
--msg-metadata=$(srcdir)/message-metadata.ini \
--outheaders-dir=_ipdlheaders \
--outcpp-dir=. \
$(IPDLDIRS:%=-I%) \

View File

@ -23,6 +23,8 @@ op.add_option('-I', '--include', dest='includedirs', default=[ ],
help='Additional directory to search for included protocol specifications')
op.add_option('-s', '--sync-msg-list', dest='syncMsgList', default='sync-messages.ini',
help="Config file listing allowed sync messages")
op.add_option('-m', '--msg-metadata', dest='msgMetadata', default='message-metadata.ini',
help="Predicted message sizes for reducing serialization malloc overhead.")
op.add_option('-v', '--verbose', dest='verbosity', default=1, action='count',
help='Verbose logging (specify -vv or -vvv for very verbose logging)')
op.add_option('-q', '--quiet', dest='verbosity', action='store_const', const=0,
@ -41,6 +43,7 @@ to be generated""")
options, files = op.parse_args()
_verbosity = options.verbosity
syncMsgList = options.syncMsgList
msgMetadata = options.msgMetadata
headersdir = options.headersdir
cppdir = options.cppdir
includedirs = [ os.path.abspath(incdir) for incdir in options.includedirs ]
@ -109,6 +112,7 @@ log(2, 'Generated C++ headers will be generated relative to "%s"', headersdir)
log(2, 'Generated C++ sources will be generated in "%s"', cppdir)
allmessages = {}
allmessageprognames = []
allprotocols = []
def normalizedFilename(f):
@ -121,6 +125,18 @@ parser = RawConfigParser()
parser.readfp(open(options.syncMsgList))
syncMsgList = parser.sections()
# Read message metadata. Right now we only have 'segment_capacity'
# for the standard segment size used for serialization.
log(2, 'Reading message metadata...')
msgMetadataConfig = RawConfigParser()
msgMetadataConfig.readfp(open(options.msgMetadata))
segmentCapacityDict = {}
for msgName in msgMetadataConfig.sections():
if msgMetadataConfig.has_option(msgName, 'segment_capacity'):
capacity = msgMetadataConfig.get(msgName, 'segment_capacity')
segmentCapacityDict[msgName] = capacity
# First pass: parse and type-check all protocols
for f in files:
log(2, os.path.basename(f))
@ -160,14 +176,25 @@ for f in files:
# Read from parser cache
filename = normalizedFilename(f)
ast = ipdl.parse(None, filename, includedirs=includedirs)
ipdl.gencxx(filename, ast, headersdir, cppdir)
ipdl.gencxx(filename, ast, headersdir, cppdir, segmentCapacityDict)
if ast.protocol:
allmessages[ast.protocol.name] = ipdl.genmsgenum(ast)
allprotocols.append('%sMsgStart' % ast.protocol.name)
# e.g. PContent::RequestMemoryReport (not prefixed or suffixed.)
for md in ast.protocol.messageDecls:
allmessageprognames.append('%s::%s' % (md.namespace, md.decl.progname))
allprotocols.sort()
# Check if we have undefined message names in segmentCapacityDict.
# This is a fool-proof of the 'message-metadata.ini' file.
undefinedMessages = set(segmentCapacityDict.keys()) - set(allmessageprognames)
if len(undefinedMessages) > 0:
print >>sys.stderr, 'Error: Undefined message names in message-metadata.ini:'
print >>sys.stderr, undefinedMessages
sys.exit(1)
ipcmsgstart = StringIO()
print >>ipcmsgstart, """

View File

@ -41,8 +41,8 @@ def typecheck(ast, errout=sys.stderr):
return TypeCheck().check(ast, errout)
def gencxx(ipdlfilename, ast, outheadersdir, outcppdir):
headers, cpps = LowerToCxx().lower(ast)
def gencxx(ipdlfilename, ast, outheadersdir, outcppdir, segmentcapacitydict):
headers, cpps = LowerToCxx().lower(ast, segmentcapacitydict)
def resolveHeader(hdr):
return [

View File

@ -15,7 +15,7 @@ from ipdl.type import ActorType, TypeVisitor, builtinHeaderIncludes
## "Public" interface to lowering
##
class LowerToCxx:
def lower(self, tu):
def lower(self, tu, segmentcapacitydict):
'''returns |[ header: File ], [ cpp : File ]| representing the
lowered form of |tu|'''
# annotate the AST with IPDL/C++ IR-type stuff used later
@ -26,7 +26,7 @@ lowered form of |tu|'''
name = tu.name
pheader, pcpp = File(name +'.h'), File(name +'.cpp')
_GenerateProtocolCode().lower(tu, pheader, pcpp)
_GenerateProtocolCode().lower(tu, pheader, pcpp, segmentcapacitydict)
headers = [ pheader ]
cpps = [ pcpp ]
@ -1417,10 +1417,11 @@ class _GenerateProtocolCode(ipdl.ast.Visitor):
self.structUnionDefns = []
self.funcDefns = []
def lower(self, tu, cxxHeaderFile, cxxFile):
def lower(self, tu, cxxHeaderFile, cxxFile, segmentcapacitydict):
self.protocol = tu.protocol
self.hdrfile = cxxHeaderFile
self.cppfile = cxxFile
self.segmentcapacitydict = segmentcapacitydict
tu.accept(self)
def visitTranslationUnit(self, tu):
@ -1577,8 +1578,15 @@ class _GenerateProtocolCode(ipdl.ast.Visitor):
for md in p.messageDecls:
decls = []
# Look up the segment capacity used for serializing this
# message. If the capacity is not specified, use '0' for
# the default capacity (defined in ipc_message.cc)
name = '%s::%s' % (md.namespace, md.decl.progname)
segmentcapacity = self.segmentcapacitydict.get(name, 0)
mfDecl, mfDefn = _splitFuncDeclDefn(
_generateMessageConstructor(md.msgCtorFunc(), md.msgId(),
segmentcapacity,
md.decl.type.nested,
md.decl.type.prio,
md.prettyMsgName(p.name+'::'),
@ -1590,6 +1598,7 @@ class _GenerateProtocolCode(ipdl.ast.Visitor):
rfDecl, rfDefn = _splitFuncDeclDefn(
_generateMessageConstructor(
md.replyCtorFunc(), md.replyId(),
0,
md.decl.type.nested,
md.decl.type.prio,
md.prettyReplyName(p.name+'::'),
@ -1692,7 +1701,7 @@ class _GenerateProtocolCode(ipdl.ast.Visitor):
##--------------------------------------------------
def _generateMessageConstructor(clsname, msgid, nested, prio, prettyName, compress):
def _generateMessageConstructor(clsname, msgid, segmentSize, nested, prio, prettyName, compress):
routingId = ExprVar('routingId')
func = FunctionDefn(FunctionDecl(
@ -1726,6 +1735,7 @@ def _generateMessageConstructor(clsname, msgid, nested, prio, prettyName, compre
StmtReturn(ExprNew(Type('IPC::Message'),
args=[ routingId,
ExprVar(msgid),
ExprLiteral.Int(int(segmentSize)),
ExprVar(nestedEnum),
ExprVar(prioEnum),
compression,

View File

@ -0,0 +1,31 @@
#############################################################
# #
# Any changes to this file must be reviewed by an IPC peer. #
# #
#############################################################
[PContent::AccumulateChildKeyedHistograms]
segment_capacity = 16384
[PContent::AccumulateChildHistograms]
segment_capacity = 16384
[PLayerTransaction::Update]
segment_capacity = 8192
[PContent::StoreAndBroadcastBlobURLRegistration]
segment_capacity = 8192
[PHttpChannel::OnStartRequest]
segment_capacity = 8192
[PHttpChannel::Redirect1Begin]
segment_capacity = 8192
[PHttpBackgroundChannel::OnTransportAndData]
segment_capacity = 8192
[PNecko::PHttpChannelConstructor]
segment_capacity = 8192
[PWyciwygChannel::WriteToCacheEntry]
segment_capacity = 8192
[PWyciwygChannel::SetSecurityInfo]
segment_capacity = 8192
[PMessagePort::PostMessages]
segment_capacity = 12288
[PMessagePort::ReceiveData]
segment_capacity = 12288